successful flux
This commit is contained in:
@@ -365,15 +365,9 @@ func NewKeyCertificate(bytes []byte) (key_certificate *KeyCertificate, remainder
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload := certificate.Data()
|
payload := certificate.Data()
|
||||||
if len(payload) < 5 {
|
|
||||||
err = errors.New("key certificate payload too short")
|
|
||||||
log.WithError(err).Error("Failed to parse KeyCertificate")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
versionByte := payload[0]
|
cpkTypeBytes := payload[0:2]
|
||||||
cpkTypeBytes := payload[1:3]
|
spkTypeBytes := payload[2:4]
|
||||||
spkTypeBytes := payload[3:5]
|
|
||||||
|
|
||||||
cpkType := Integer(cpkTypeBytes)
|
cpkType := Integer(cpkTypeBytes)
|
||||||
spkType := Integer(spkTypeBytes)
|
spkType := Integer(spkTypeBytes)
|
||||||
@@ -385,7 +379,6 @@ func NewKeyCertificate(bytes []byte) (key_certificate *KeyCertificate, remainder
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"version": versionByte,
|
|
||||||
"spk_type": key_certificate.SpkType.Int(),
|
"spk_type": key_certificate.SpkType.Int(),
|
||||||
"cpk_type": key_certificate.CpkType.Int(),
|
"cpk_type": key_certificate.CpkType.Int(),
|
||||||
"remainder_length": len(remainder),
|
"remainder_length": len(remainder),
|
||||||
@@ -400,24 +393,24 @@ func KeyCertificateFromCertificate(cert Certificate) (*KeyCertificate, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := cert.Data()
|
data := cert.Data()
|
||||||
fmt.Printf("Certificate Data Length: %d\n", len(data))
|
fmt.Printf("Certificate Data Length in KeyCertificateFromCertificate: %d\n", len(data))
|
||||||
fmt.Printf("Certificate Data Bytes: %v\n", data)
|
fmt.Printf("Certificate Data Bytes in KeyCertificateFromCertificate: %v\n", data)
|
||||||
|
|
||||||
if len(data) < 4 {
|
if len(data) < 4 {
|
||||||
return nil, fmt.Errorf("certificate payload too short")
|
return nil, fmt.Errorf("certificate payload too short in KeyCertificateFromCertificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
cpkTypeBytes := data[1:3]
|
cpkTypeBytes := data[0:2]
|
||||||
spkTypeBytes := data[3:5]
|
spkTypeBytes := data[2:4]
|
||||||
|
|
||||||
fmt.Printf("cpkTypeBytes: %v\n", cpkTypeBytes)
|
fmt.Printf("cpkTypeBytes in KeyCertificateFromCertificate: %v\n", cpkTypeBytes)
|
||||||
fmt.Printf("spkTypeBytes: %v\n", spkTypeBytes)
|
fmt.Printf("spkTypeBytes in KeyCertificateFromCertificate: %v\n", spkTypeBytes)
|
||||||
|
|
||||||
cpkType := Integer(cpkTypeBytes)
|
cpkType := Integer(cpkTypeBytes)
|
||||||
spkType := Integer(spkTypeBytes)
|
spkType := Integer(spkTypeBytes)
|
||||||
|
|
||||||
fmt.Printf("cpkType (Int): %d\n", cpkType.Int())
|
fmt.Printf("cpkType (Int) in KeyCertificateFromCertificate: %d\n", cpkType.Int())
|
||||||
fmt.Printf("spkType (Int): %d\n", spkType.Int())
|
fmt.Printf("spkType (Int) in KeyCertificateFromCertificate: %d\n", spkType.Int())
|
||||||
|
|
||||||
keyCert := &KeyCertificate{
|
keyCert := &KeyCertificate{
|
||||||
Certificate: cert,
|
Certificate: cert,
|
||||||
|
@@ -247,83 +247,6 @@ func ReadKeysAndCertElgAndEd25519(data []byte) (keysAndCert *KeysAndCert, remain
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func ReadKeysAndCertDeux(data []byte) (keysAndCert *KeysAndCert, remainder []byte, err error) {
|
|
||||||
dataLen := len(data)
|
|
||||||
fmt.Printf("Reading KeysAndCert from data, input_length=%d\n", dataLen)
|
|
||||||
|
|
||||||
const (
|
|
||||||
pubKeySize = 256
|
|
||||||
sigKeyMaxSize = 128
|
|
||||||
totalKeySize = 384
|
|
||||||
)
|
|
||||||
|
|
||||||
if dataLen < totalKeySize+3 {
|
|
||||||
err = fmt.Errorf("data is too short to contain KeysAndCert, dataLen=%d", dataLen)
|
|
||||||
fmt.Printf("Error: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
publicKeyData := data[:pubKeySize]
|
|
||||||
sigKeyAndPaddingData := data[pubKeySize:totalKeySize]
|
|
||||||
|
|
||||||
certStartIndex := totalKeySize
|
|
||||||
certData := data[certStartIndex:]
|
|
||||||
cert, _, err := ReadCertificate(certData)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to read Certificate: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
keyCert, err := KeyCertificateFromCertificate(cert)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to parse KeyCertificate: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
publicKey, err := keyCert.ConstructPublicKey(publicKeyData)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to construct public key: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
actualSigKeySize := keyCert.SigningPublicKeySize()
|
|
||||||
paddingSize := sigKeyMaxSize - actualSigKeySize
|
|
||||||
if paddingSize < 0 {
|
|
||||||
err = fmt.Errorf("invalid signing public key size: %d", actualSigKeySize)
|
|
||||||
fmt.Printf("Error: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
paddingData := sigKeyAndPaddingData[:paddingSize]
|
|
||||||
signingPublicKeyData := sigKeyAndPaddingData[paddingSize:sigKeyMaxSize]
|
|
||||||
|
|
||||||
signingPublicKey, err := keyCert.ConstructSigningPublicKey(signingPublicKeyData)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to construct signing public key: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
keysAndCert, err = NewKeysAndCert(
|
|
||||||
keyCert,
|
|
||||||
publicKey,
|
|
||||||
paddingData,
|
|
||||||
signingPublicKey,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to create KeysAndCert: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
remainder = data[certStartIndex+len(cert.Bytes()):]
|
|
||||||
|
|
||||||
fmt.Printf("Successfully read KeysAndCert\n")
|
|
||||||
fmt.Printf(" public_key_type: %d\n", keyCert.CpkType.Int())
|
|
||||||
fmt.Printf(" signing_public_key_type: %d\n", keyCert.SpkType.Int())
|
|
||||||
fmt.Printf(" padding_length: %d\n", len(paddingData))
|
|
||||||
fmt.Printf(" remainder_length: %d\n", len(remainder))
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func constructPublicKey(data []byte, cryptoType uint16) (crypto.PublicKey, error) {
|
func constructPublicKey(data []byte, cryptoType uint16) (crypto.PublicKey, error) {
|
||||||
switch cryptoType {
|
switch cryptoType {
|
||||||
|
@@ -69,9 +69,9 @@ func createValidKeyAndCert(t *testing.T) *KeysAndCert {
|
|||||||
payload.Write(*cryptoPublicKeyType)
|
payload.Write(*cryptoPublicKeyType)
|
||||||
|
|
||||||
// Create certificate
|
// Create certificate
|
||||||
cert, err := certificate.NewCertificateWithType(certificate.CERT_KEY, payload.Bytes())
|
cert, err := certificate.NewCertificateDeux(certificate.CERT_KEY, payload.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create certificate: %v\n", err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keyCert, err := key_certificate.KeyCertificateFromCertificate(*cert)
|
keyCert, err := key_certificate.KeyCertificateFromCertificate(*cert)
|
||||||
@@ -120,25 +120,6 @@ func TestCertificateWithValidDataElgAndEd25519(t *testing.T) {
|
|||||||
assert.Equal(keysAndCert.signingPublicKey.Bytes(), parsedKeysAndCert.signingPublicKey.Bytes(), "SigningPublicKeys should match")
|
assert.Equal(keysAndCert.signingPublicKey.Bytes(), parsedKeysAndCert.signingPublicKey.Bytes(), "SigningPublicKeys should match")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCertificateWithValidDataDeux(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
keysAndCert := createValidKeyAndCert(t)
|
|
||||||
|
|
||||||
// Serialize KeysAndCert to bytes
|
|
||||||
serialized := keysAndCert.Bytes()
|
|
||||||
|
|
||||||
// Deserialize KeysAndCert from bytes
|
|
||||||
parsedKeysAndCert, remainder, err := ReadKeysAndCertDeux(serialized)
|
|
||||||
assert.Nil(err, "ReadKeysAndCert should not error with valid data")
|
|
||||||
assert.Empty(remainder, "There should be no remainder after parsing KeysAndCert")
|
|
||||||
|
|
||||||
// Compare individual fields
|
|
||||||
assert.Equal(keysAndCert.KeyCertificate.Bytes(), parsedKeysAndCert.KeyCertificate.Bytes(), "KeyCertificates should match")
|
|
||||||
assert.Equal(keysAndCert.publicKey.Bytes(), parsedKeysAndCert.publicKey.Bytes(), "PublicKeys should match")
|
|
||||||
assert.Equal(keysAndCert.Padding, parsedKeysAndCert.Padding, "Padding should match")
|
|
||||||
assert.Equal(keysAndCert.signingPublicKey.Bytes(), parsedKeysAndCert.signingPublicKey.Bytes(), "SigningPublicKeys should match")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCertificateWithValidDataManual(t *testing.T) {
|
func TestCertificateWithValidDataManual(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
@@ -206,14 +206,14 @@ func ReadDestinationFromLeaseSet(data []byte) (destination Destination, remainde
|
|||||||
|
|
||||||
destinationData := data[:destinationLength]
|
destinationData := data[:destinationLength]
|
||||||
|
|
||||||
keysAndCert, _, err := ReadKeysAndCertDeux(destinationData)
|
keysAndCert, _, err := ReadKeysAndCert(destinationData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to read KeysAndCert: %v\n", err)
|
fmt.Printf("Failed to read KeysAndCert: %v\n", err) //32 / 0 error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
destination = Destination{
|
destination = Destination{
|
||||||
KeysAndCert: *keysAndCert,
|
KeysAndCert: keysAndCert,
|
||||||
}
|
}
|
||||||
|
|
||||||
remainder = data[destinationLength:]
|
remainder = data[destinationLength:]
|
||||||
|
@@ -68,9 +68,6 @@ func generateTestRouterInfo(t *testing.T) (*router_info.RouterInfo, crypto.Publi
|
|||||||
// Create KeyCertificate specifying key types
|
// Create KeyCertificate specifying key types
|
||||||
var payload bytes.Buffer
|
var payload bytes.Buffer
|
||||||
|
|
||||||
versionByte := byte(0x00)
|
|
||||||
payload.WriteByte(versionByte)
|
|
||||||
|
|
||||||
signingPublicKeyType, err := data.NewIntegerFromInt(key_certificate.KEYCERT_SIGN_ED25519, 2)
|
signingPublicKeyType, err := data.NewIntegerFromInt(key_certificate.KEYCERT_SIGN_ED25519, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create signing public key type integer: %v", err)
|
t.Fatalf("Failed to create signing public key type integer: %v", err)
|
||||||
@@ -221,8 +218,6 @@ func generateTestDestination(t *testing.T) (*destination.Destination, crypto.Pub
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create signing public key type integer: %v", err)
|
t.Fatalf("Failed to create signing public key type integer: %v", err)
|
||||||
}
|
}
|
||||||
versionByte := byte(0x00)
|
|
||||||
payload.WriteByte(versionByte)
|
|
||||||
payload.Write(*cryptoPublicKeyType)
|
payload.Write(*cryptoPublicKeyType)
|
||||||
payload.Write(*signingPublicKeyType)
|
payload.Write(*signingPublicKeyType)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user