Output the rest of the key certificate, that would probably help...

This commit is contained in:
eyedeekay
2024-11-10 17:15:56 -05:00
parent 63c48dd3b7
commit a29fa0bc03
9 changed files with 51 additions and 9 deletions

View File

@@ -172,14 +172,14 @@ func readCertificate(data []byte) (certificate Certificate, err error) {
default:
certificate.kind = Integer(data[0:1])
certificate.len = Integer(data[1:3])
payleng := len(data) - CERT_MIN_SIZE
payloadLength := len(data) - CERT_MIN_SIZE
certificate.payload = data[CERT_MIN_SIZE:]
if certificate.len.Int() > len(data)-CERT_MIN_SIZE {
err = fmt.Errorf("certificate parsing warning: certificate data is shorter than specified by length")
log.WithFields(logrus.Fields{
"at": "(Certificate) NewCertificate",
"certificate_bytes_length": certificate.len.Int(),
"certificate_payload_length": payleng,
"certificate_payload_length": payloadLength,
"data_bytes:": string(data),
"kind_bytes": data[0:1],
"len_bytes": data[1:3],

View File

@@ -88,6 +88,9 @@ func (keys_and_cert KeysAndCert) Bytes() []byte {
log.WithFields(logrus.Fields{
"bytes_length": len(bytes),
}).Debug("Retrieved bytes from KeysAndCert")
bytes = append(bytes, keys_and_cert.publicKey.Bytes()...)
bytes = append(bytes, keys_and_cert.Padding...)
bytes = append(bytes, keys_and_cert.signingPublicKey.Bytes()...)
return bytes
}

View File

@@ -137,17 +137,30 @@ func (router_info RouterInfo) Bytes() (bytes []byte, err error) {
return bytes, err
}
// Convert a byte slice into a string like [1, 2, 3] -> "1, 2, 3"
func bytesToString(bytes []byte) string {
str := "["
for i, b := range bytes {
str += strconv.Itoa(int(b))
if i < len(bytes)-1 {
str += ", "
}
}
str += "]"
return str
}
func (router_info RouterInfo) String() string {
log.Debug("Converting RouterInfo to string")
str := "Certificate: " + string(router_info.router_identity.Bytes())
str += "Published: " + string(router_info.published.Bytes())
str += "Addresses:" + string(router_info.size.Bytes())
str := "Certificate: " + bytesToString(router_info.router_identity.Bytes())
str += "Published: " + bytesToString(router_info.published.Bytes())
str += "Addresses:" + bytesToString(router_info.size.Bytes())
for index, router_address := range router_info.addresses {
str += "Address " + strconv.Itoa(index) + ": " + router_address.String()
}
str += "Peer Size: " + string(router_info.peer_size.Bytes())
str += "Options: " + string(router_info.options.Data())
str += "Signature: " + string([]byte(*router_info.signature))
str += "Peer Size: " + bytesToString(router_info.peer_size.Bytes())
str += "Options: " + bytesToString(router_info.options.Data())
str += "Signature: " + bytesToString([]byte(*router_info.signature))
log.WithField("string_length", len(str)).Debug("Converted RouterInfo to string")
return str
}

View File

@@ -98,7 +98,7 @@ func TestCreateRouterInfo(t *testing.T) {
t.Run("Serialize and Deserialize RouterInfo", func(t *testing.T) {
routerInfoBytes, err := routerInfo.Bytes()
t.Log(routerInfo.String(), routerInfoBytes)
t.Log(len(routerInfoBytes), routerInfo.String(), routerInfoBytes)
if err != nil {
t.Fatalf("Failed to write RouterInfo to bytes: %v\n", err)
}

View File

@@ -95,6 +95,10 @@ type DSAVerifier struct {
type DSAPublicKey [128]byte
func (k DSAPublicKey) Bytes() []byte {
return k[:]
}
// create a new dsa verifier
func (k DSAPublicKey) NewVerifier() (v Verifier, err error) {
log.Debug("Creating new DSA verifier")

View File

@@ -73,6 +73,10 @@ func (k ECP256PublicKey) Len() int {
return len(k)
}
func (k ECP256PublicKey) Bytes() []byte {
return k[:]
}
func (k ECP256PublicKey) NewVerifier() (Verifier, error) {
log.Debug("Creating new P256 ECDSA verifier")
// return createECVerifier(elliptic.P256(), crypto.SHA256, k[:])
@@ -88,6 +92,10 @@ type (
ECP384PrivateKey [48]byte
)
func (k ECP384PublicKey) Bytes() []byte {
return k[:]
}
func (k ECP384PublicKey) Len() int {
return len(k)
}
@@ -107,6 +115,10 @@ type (
ECP521PrivateKey [66]byte
)
func (k ECP521PublicKey) Bytes() []byte {
return k[:]
}
func (k ECP521PublicKey) Len() int {
return len(k)
}

View File

@@ -34,6 +34,10 @@ func (k Ed25519PublicKey) Len() int {
return len(k)
}
func (k Ed25519PublicKey) Bytes() []byte {
return k
}
func createEd25519PublicKey(data []byte) (k *ed25519.PublicKey) {
log.WithField("data_length", len(data)).Debug("Creating Ed25519 public key")
if len(data) == 256 {

View File

@@ -237,6 +237,10 @@ func (elg ElgPublicKey) Len() int {
return len(elg)
}
func (elg ElgPublicKey) Bytes() []byte {
return elg[:]
}
func (elg ElgPublicKey) NewEncrypter() (enc Encrypter, err error) {
log.Debug("Creating new ElGamal encrypter")
k := createElgamalPublicKey(elg[:])

View File

@@ -26,9 +26,11 @@ type SigningPublicKey interface {
NewVerifier() (Verifier, error)
// get the size of this public key
Len() int
Bytes() []byte
}
type PublicKey interface {
Len() int
Bytes() []byte
NewEncrypter() (Encrypter, error)
}