# Week5 Update
## TL;DR
1. Add protobuf marshaling/unmarshaling dependency and generate codes for keys.proto below. Open the [PR](https://github.com/zen-eth/zig-libp2p/pull/34).
```protobuf
syntax = "proto2";
enum KeyType {
RSA = 0;
Ed25519 = 1;
Secp256k1 = 2;
ECDSA = 3;
}
message PublicKey {
required KeyType Type = 1;
required bytes Data = 2;
}
```
2. Implement X509 certification creation follow the [libp2p tls spec](https://github.com/libp2p/specs/blob/master/tls/tls.md#libp2p-public-key-extension), open the [PR](https://github.com/zen-eth/zig-libp2p/pull/37).
## Protobuf in Zig
Follow the libp2p tls spec, it need add hostKey into X509 cert extension. It need marshal host public key using protobuf. However libp2p still use proto2 version, Zig's protobuf library either only supports proto3, or many of them are no longer maintained.
### Solution 1
Use protobuf-c to implement.
- Add runtime dependency [protobuf-c](https://github.com/allyourcodebase/protobuf-c).
- Generate C files using proto-c generator.
- Use the C API.
### Solution 2
There is a [Zig proto lib](https://github.com/octopus-foundation/gremlin.zig) which compatible with Protocol Buffers version 2 and 3.
Currently we choose solution 2 and will try to verify if it works well.
## X509 certification in Zig
Since the Zig standard lib not well support X509, refer to the [cpp-libp2p](https://github.com/libp2p/cpp-libp2p/blob/master/src/security/tls/tls_details.cpp#L295) and [Sig](https://github.com/Syndica/sig/blob/c807735ab5dc968afd70e2171d3579a84fb2df60/src/net/quic_client.zig#L509), I try to create certificate by using Boringssl/Openssl C API directly in the [PR](https://github.com/zen-eth/zig-libp2p/pull/37).
Besides creating a self-signed X509 cert, follow the libp2p spec, add the specific extensions.
- Use host private key to sign the subject public key der.
- Use protobuf to marshal the host public key.
## Next
Try to complete dialing side for `QuicTransport`, and start to test `QuicTransport` dialing and listening.
For TLS handshake verification, we need wait the peerid feature in this [issue](https://github.com/zen-eth/zig-libp2p/issues/18).