2022-09-12 08:31:02 +00:00
|
|
|
// Package key_certificate implements the I2P Destination common data structure
|
2022-07-11 23:41:58 -04:00
|
|
|
package key_certificate
|
2016-02-05 02:23:11 -08:00
|
|
|
|
2016-02-14 23:10:37 -08:00
|
|
|
/*
|
|
|
|
I2P Key Certificate
|
2016-06-16 23:17:21 -07:00
|
|
|
https://geti2p.net/spec/common-structures#certificate
|
2016-02-14 23:10:37 -08:00
|
|
|
Accurate for version 0.9.24
|
2016-02-20 19:02:55 -08:00
|
|
|
|
|
|
|
+----+----+----+----+----+-//
|
|
|
|
|type| length | payload
|
|
|
|
+----+----+----+----+----+-//
|
|
|
|
|
|
|
|
type :: Integer
|
|
|
|
length -> 1 byte
|
|
|
|
|
|
|
|
case 0 -> NULL
|
|
|
|
case 1 -> HASHCASH
|
|
|
|
case 2 -> HIDDEN
|
|
|
|
case 3 -> SIGNED
|
|
|
|
case 4 -> MULTIPLE
|
|
|
|
case 5 -> KEY
|
|
|
|
|
|
|
|
length :: Integer
|
|
|
|
length -> 2 bytes
|
|
|
|
|
|
|
|
payload :: data
|
|
|
|
length -> $length bytes
|
2016-02-14 23:10:37 -08:00
|
|
|
*/
|
|
|
|
|
2016-02-05 02:23:11 -08:00
|
|
|
import (
|
2016-02-13 21:00:29 -08:00
|
|
|
"errors"
|
2024-10-18 13:22:36 -04:00
|
|
|
|
2024-10-18 12:27:42 -04:00
|
|
|
"github.com/go-i2p/go-i2p/lib/util/logger"
|
|
|
|
"github.com/sirupsen/logrus"
|
2022-04-27 10:48:59 -04:00
|
|
|
|
2022-05-22 19:59:20 -04:00
|
|
|
. "github.com/go-i2p/go-i2p/lib/common/certificate"
|
|
|
|
. "github.com/go-i2p/go-i2p/lib/common/data"
|
2021-04-19 20:43:37 -04:00
|
|
|
"github.com/go-i2p/go-i2p/lib/crypto"
|
2016-02-05 02:23:11 -08:00
|
|
|
)
|
|
|
|
|
2024-10-18 12:27:42 -04:00
|
|
|
var log = logger.GetLogger()
|
|
|
|
|
2016-02-13 21:00:29 -08:00
|
|
|
// Key Certificate Signing Key Types
|
|
|
|
const (
|
|
|
|
KEYCERT_SIGN_DSA_SHA1 = iota
|
|
|
|
KEYCERT_SIGN_P256
|
|
|
|
KEYCERT_SIGN_P384
|
|
|
|
KEYCERT_SIGN_P521
|
|
|
|
KEYCERT_SIGN_RSA2048
|
|
|
|
KEYCERT_SIGN_RSA3072
|
|
|
|
KEYCERT_SIGN_RSA4096
|
|
|
|
KEYCERT_SIGN_ED25519
|
|
|
|
KEYCERT_SIGN_ED25519PH
|
|
|
|
)
|
2016-02-05 02:23:11 -08:00
|
|
|
|
2016-02-13 21:00:29 -08:00
|
|
|
// Key Certificate Public Key Types
|
|
|
|
const (
|
|
|
|
KEYCERT_CRYPTO_ELG = iota
|
2024-10-03 21:31:54 -04:00
|
|
|
KEYCERT_CRYPTO_P256
|
|
|
|
KEYCERT_CRYPTO_P384
|
|
|
|
KEYCERT_CRYPTO_P521
|
|
|
|
KEYCERT_CRYPTO_X25519
|
2016-02-13 21:00:29 -08:00
|
|
|
)
|
|
|
|
|
2022-04-27 10:48:59 -04:00
|
|
|
const (
|
|
|
|
KEYCERT_MIN_SIZE = 7
|
|
|
|
)
|
|
|
|
|
2016-02-13 21:00:29 -08:00
|
|
|
// SigningPublicKey sizes for Signing Key Types
|
|
|
|
const (
|
|
|
|
KEYCERT_SIGN_DSA_SHA1_SIZE = 128
|
|
|
|
KEYCERT_SIGN_P256_SIZE = 64
|
|
|
|
KEYCERT_SIGN_P384_SIZE = 96
|
|
|
|
KEYCERT_SIGN_P521_SIZE = 132
|
|
|
|
KEYCERT_SIGN_RSA2048_SIZE = 256
|
|
|
|
KEYCERT_SIGN_RSA3072_SIZE = 384
|
|
|
|
KEYCERT_SIGN_RSA4096_SIZE = 512
|
|
|
|
KEYCERT_SIGN_ED25519_SIZE = 32
|
|
|
|
KEYCERT_SIGN_ED25519PH_SIZE = 32
|
|
|
|
)
|
|
|
|
|
|
|
|
// PublicKey sizes for Public Key Types
|
|
|
|
const (
|
2024-10-03 21:31:54 -04:00
|
|
|
KEYCERT_CRYPTO_ELG_SIZE = 256
|
|
|
|
KEYCERT_CRYPTO_P256_SIZE = 64
|
|
|
|
KEYCERT_CRYPTO_P384_SIZE = 96
|
|
|
|
KEYCERT_CRYPTO_P521_SIZE = 132
|
|
|
|
KEYCERT_CRYPTO_X25519_SIZE = 32
|
2016-02-13 21:00:29 -08:00
|
|
|
)
|
|
|
|
|
2016-06-17 21:07:16 -07:00
|
|
|
// Sizes of structures in KeyCertificates
|
2016-02-16 01:04:40 -08:00
|
|
|
const (
|
|
|
|
KEYCERT_PUBKEY_SIZE = 256
|
|
|
|
KEYCERT_SPK_SIZE = 128
|
|
|
|
)
|
|
|
|
|
2024-10-03 21:31:54 -04:00
|
|
|
// type KeyCertificate []byte
|
2022-04-27 10:48:59 -04:00
|
|
|
type KeyCertificate struct {
|
2024-10-03 21:31:54 -04:00
|
|
|
Certificate
|
2022-04-27 10:48:59 -04:00
|
|
|
spkType Integer
|
|
|
|
cpkType Integer
|
|
|
|
}
|
2016-02-05 02:23:11 -08:00
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// Data returns the raw []byte contained in the Certificate.
|
2016-02-05 02:23:11 -08:00
|
|
|
func (key_certificate KeyCertificate) Data() ([]byte, error) {
|
2024-10-18 12:27:42 -04:00
|
|
|
data := key_certificate.Certificate.RawBytes()
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"data_length": len(data),
|
|
|
|
}).Debug("Retrieved raw data from KeyCertificate")
|
2022-04-27 10:48:59 -04:00
|
|
|
return key_certificate.Certificate.RawBytes(), nil
|
2016-02-05 02:23:11 -08:00
|
|
|
}
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// SigningPublicKeyType returns the SigningPublicKey type as a Go integer.
|
2022-04-27 10:48:59 -04:00
|
|
|
func (key_certificate KeyCertificate) SigningPublicKeyType() (signing_pubkey_type int) {
|
2024-10-18 12:27:42 -04:00
|
|
|
signing_pubkey_type = key_certificate.spkType.Int()
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"signing_pubkey_type": signing_pubkey_type,
|
|
|
|
}).Debug("Retrieved SigningPublicKey type")
|
2022-04-27 10:48:59 -04:00
|
|
|
return key_certificate.spkType.Int()
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// PublicKeyType returns the PublicKey type as a Go integer.
|
2022-04-27 10:48:59 -04:00
|
|
|
func (key_certificate KeyCertificate) PublicKeyType() (pubkey_type int) {
|
2024-10-18 12:27:42 -04:00
|
|
|
pubkey_type = key_certificate.cpkType.Int()
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"pubkey_type": pubkey_type,
|
|
|
|
}).Debug("Retrieved PublicKey type")
|
2022-04-27 10:48:59 -04:00
|
|
|
return key_certificate.cpkType.Int()
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// ConstructPublicKey returns a PublicKey constructed using any excess data that may be stored in the KeyCertififcate.
|
|
|
|
// Returns enr errors encountered while parsing.
|
2016-02-13 21:00:29 -08:00
|
|
|
func (key_certificate KeyCertificate) ConstructPublicKey(data []byte) (public_key crypto.PublicKey, err error) {
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"input_length": len(data),
|
|
|
|
}).Debug("Constructing PublicKey from KeyCertificate")
|
2022-04-27 10:48:59 -04:00
|
|
|
key_type := key_certificate.PublicKeyType()
|
2016-02-13 21:00:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2016-02-16 01:04:40 -08:00
|
|
|
data_len := len(data)
|
2024-10-03 21:31:54 -04:00
|
|
|
if data_len < key_certificate.CryptoSize() {
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
2016-06-16 23:04:03 -07:00
|
|
|
"at": "(KeyCertificate) ConstructPublicKey",
|
2016-02-16 01:04:40 -08:00
|
|
|
"data_len": data_len,
|
|
|
|
"required_len": KEYCERT_PUBKEY_SIZE,
|
|
|
|
"reason": "not enough data",
|
|
|
|
}).Error("error constructing public key")
|
2016-02-20 19:02:55 -08:00
|
|
|
err = errors.New("error constructing public key: not enough data")
|
2016-02-13 21:00:29 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
switch key_type {
|
|
|
|
case KEYCERT_CRYPTO_ELG:
|
|
|
|
var elg_key crypto.ElgPublicKey
|
2016-02-16 01:04:40 -08:00
|
|
|
copy(elg_key[:], data[KEYCERT_PUBKEY_SIZE-KEYCERT_CRYPTO_ELG_SIZE:KEYCERT_PUBKEY_SIZE])
|
2016-02-13 21:00:29 -08:00
|
|
|
public_key = elg_key
|
2024-10-18 12:27:42 -04:00
|
|
|
log.Debug("Constructed ElgPublicKey")
|
2024-10-03 21:31:54 -04:00
|
|
|
case KEYCERT_CRYPTO_X25519:
|
|
|
|
var ed25519_key crypto.Ed25519PublicKey
|
|
|
|
copy(ed25519_key[:], data[KEYCERT_PUBKEY_SIZE-KEYCERT_CRYPTO_ELG_SIZE:KEYCERT_PUBKEY_SIZE])
|
|
|
|
public_key = ed25519_key
|
2024-10-18 12:27:42 -04:00
|
|
|
log.Debug("Constructed Ed25519PublicKey")
|
|
|
|
default:
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"key_type": key_type,
|
|
|
|
}).Warn("Unknown public key type")
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
2024-10-18 12:27:42 -04:00
|
|
|
|
2016-02-13 21:00:29 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// ConstructSigningPublicKey returns a SingingPublicKey constructed using any excess data that may be stored in the KeyCertificate.
|
|
|
|
// Returns any errors encountered while parsing.
|
2016-02-20 19:02:55 -08:00
|
|
|
func (key_certificate KeyCertificate) ConstructSigningPublicKey(data []byte) (signing_public_key crypto.SigningPublicKey, err error) {
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"input_length": len(data),
|
|
|
|
}).Debug("Constructing SigningPublicKey from KeyCertificate")
|
2022-04-27 10:48:59 -04:00
|
|
|
signing_key_type := key_certificate.PublicKeyType()
|
2016-02-13 21:00:29 -08:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2016-02-16 01:04:40 -08:00
|
|
|
data_len := len(data)
|
2024-10-03 21:31:54 -04:00
|
|
|
if data_len < key_certificate.SignatureSize() {
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
2016-06-16 23:04:03 -07:00
|
|
|
"at": "(KeyCertificate) ConstructSigningPublicKey",
|
2016-02-16 01:04:40 -08:00
|
|
|
"data_len": data_len,
|
|
|
|
"required_len": KEYCERT_SPK_SIZE,
|
|
|
|
"reason": "not enough data",
|
|
|
|
}).Error("error constructing signing public key")
|
2016-02-20 19:02:55 -08:00
|
|
|
err = errors.New("error constructing signing public key: not enough data")
|
2016-02-13 21:00:29 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
switch signing_key_type {
|
|
|
|
case KEYCERT_SIGN_DSA_SHA1:
|
|
|
|
var dsa_key crypto.DSAPublicKey
|
2016-02-16 01:04:40 -08:00
|
|
|
copy(dsa_key[:], data[KEYCERT_SPK_SIZE-KEYCERT_SIGN_DSA_SHA1_SIZE:KEYCERT_SPK_SIZE])
|
2016-02-13 21:00:29 -08:00
|
|
|
signing_public_key = dsa_key
|
2024-10-18 12:27:42 -04:00
|
|
|
log.Debug("Constructed DSAPublicKey")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_P256:
|
|
|
|
var ec_key crypto.ECP256PublicKey
|
2016-02-16 01:04:40 -08:00
|
|
|
copy(ec_key[:], data[KEYCERT_SPK_SIZE-KEYCERT_SIGN_P256_SIZE:KEYCERT_SPK_SIZE])
|
2016-02-13 21:00:29 -08:00
|
|
|
signing_public_key = ec_key
|
2024-10-18 12:27:42 -04:00
|
|
|
log.Debug("Constructed ECP256PublicKey")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_P384:
|
|
|
|
var ec_key crypto.ECP384PublicKey
|
2016-02-16 01:04:40 -08:00
|
|
|
copy(ec_key[:], data[KEYCERT_SPK_SIZE-KEYCERT_SIGN_P384_SIZE:KEYCERT_SPK_SIZE])
|
2016-02-13 21:00:29 -08:00
|
|
|
signing_public_key = ec_key
|
2024-10-18 12:27:42 -04:00
|
|
|
log.Debug("Constructed ECP384PublicKey")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_P521:
|
|
|
|
var ec_key crypto.ECP521PublicKey
|
2016-02-16 01:04:40 -08:00
|
|
|
extra := KEYCERT_SIGN_P521_SIZE - KEYCERT_SPK_SIZE
|
2016-02-13 21:00:29 -08:00
|
|
|
copy(ec_key[:], data)
|
2022-04-27 10:48:59 -04:00
|
|
|
copy(ec_key[KEYCERT_SPK_SIZE:], key_certificate.Certificate.RawBytes()[4:4+extra])
|
2016-02-13 21:00:29 -08:00
|
|
|
signing_public_key = ec_key
|
2024-10-18 12:27:42 -04:00
|
|
|
log.Debug("Constructed ECP521PublicKey")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_RSA2048:
|
2024-10-03 21:31:54 -04:00
|
|
|
// var rsa_key crypto.RSA2048PublicKey
|
|
|
|
// extra := KEYCERT_SIGN_RSA2048_SIZE - 128
|
|
|
|
// copy(rsa_key[:], data)
|
|
|
|
// copy(rsa_key[128:], key_certificate[4:4+extra])
|
|
|
|
// signing_public_key = rsa_key
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"signing_key_type": signing_key_type,
|
|
|
|
}).Warn("Signing key type KEYCERT_SIGN_RSA2048 not implemented")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_RSA3072:
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"signing_key_type": signing_key_type,
|
|
|
|
}).Warn("Signing key type KEYCERT_SIGN_RSA3072 not implemented")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_RSA4096:
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"signing_key_type": signing_key_type,
|
|
|
|
}).Warn("Signing key type KEYCERT_SIGN_RSA4096 not implemented")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_ED25519:
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"signing_key_type": signing_key_type,
|
|
|
|
}).Warn("Signing key type KEYCERT_SIGN_ED25519 not implemented")
|
2016-02-13 21:00:29 -08:00
|
|
|
case KEYCERT_SIGN_ED25519PH:
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"signing_key_type": signing_key_type,
|
|
|
|
}).Warn("Signing key type KEYCERT_SIGN_ED25519PH not implemented")
|
|
|
|
default:
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"signing_key_type": signing_key_type,
|
|
|
|
}).Warn("Unknown signing key type")
|
2016-02-13 21:00:29 -08:00
|
|
|
}
|
2024-10-18 12:27:42 -04:00
|
|
|
|
2016-02-05 02:23:11 -08:00
|
|
|
return
|
|
|
|
}
|
2016-02-14 22:28:20 -08:00
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// SignatureSize return the size of a Signature corresponding to the Key Certificate's SigningPublicKey type.
|
2016-02-14 22:28:20 -08:00
|
|
|
func (key_certificate KeyCertificate) SignatureSize() (size int) {
|
|
|
|
sizes := map[int]int{
|
2024-10-03 21:31:54 -04:00
|
|
|
KEYCERT_SIGN_DSA_SHA1: KEYCERT_SIGN_DSA_SHA1_SIZE,
|
|
|
|
KEYCERT_SIGN_P256: KEYCERT_SIGN_P256_SIZE,
|
|
|
|
KEYCERT_SIGN_P384: KEYCERT_SIGN_P384_SIZE,
|
|
|
|
KEYCERT_SIGN_P521: KEYCERT_SIGN_P521_SIZE,
|
|
|
|
KEYCERT_SIGN_RSA2048: KEYCERT_SIGN_RSA2048_SIZE,
|
|
|
|
KEYCERT_SIGN_RSA3072: KEYCERT_SIGN_RSA3072_SIZE,
|
|
|
|
KEYCERT_SIGN_RSA4096: KEYCERT_SIGN_RSA4096_SIZE,
|
|
|
|
KEYCERT_SIGN_ED25519: KEYCERT_SIGN_ED25519_SIZE,
|
|
|
|
KEYCERT_SIGN_ED25519PH: KEYCERT_SIGN_ED25519PH_SIZE,
|
2016-02-14 22:28:20 -08:00
|
|
|
}
|
2022-04-27 10:48:59 -04:00
|
|
|
key_type := key_certificate.SigningPublicKeyType()
|
2024-10-18 12:27:42 -04:00
|
|
|
size = sizes[int(key_type)]
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"key_type": key_type,
|
|
|
|
"signature_size": size,
|
|
|
|
}).Debug("Retrieved signature size")
|
2016-02-14 22:28:20 -08:00
|
|
|
return sizes[int(key_type)]
|
|
|
|
}
|
2022-04-27 10:48:59 -04:00
|
|
|
|
2024-10-03 21:31:54 -04:00
|
|
|
// CryptoSize return the size of a Public Key corresponding to the Key Certificate's PublicKey type.
|
|
|
|
func (key_certificate KeyCertificate) CryptoSize() (size int) {
|
|
|
|
sizes := map[int]int{
|
|
|
|
KEYCERT_CRYPTO_ELG: KEYCERT_CRYPTO_ELG_SIZE,
|
|
|
|
KEYCERT_CRYPTO_P256: KEYCERT_CRYPTO_P256_SIZE,
|
|
|
|
KEYCERT_CRYPTO_P384: KEYCERT_CRYPTO_P384_SIZE,
|
|
|
|
KEYCERT_CRYPTO_P521: KEYCERT_CRYPTO_P521_SIZE,
|
|
|
|
KEYCERT_CRYPTO_X25519: KEYCERT_CRYPTO_X25519_SIZE,
|
|
|
|
}
|
|
|
|
key_type := key_certificate.PublicKeyType()
|
2024-10-18 12:27:42 -04:00
|
|
|
size = sizes[int(key_type)]
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"key_type": key_type,
|
|
|
|
"crypto_size": size,
|
|
|
|
}).Debug("Retrieved crypto size")
|
2024-10-03 21:31:54 -04:00
|
|
|
return sizes[int(key_type)]
|
|
|
|
}
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// NewKeyCertificate creates a new *KeyCertificate from []byte using ReadCertificate.
|
|
|
|
// The remaining bytes after the specified length are also returned.
|
|
|
|
// Returns a list of errors that occurred during parsing.
|
2022-05-09 20:43:24 -04:00
|
|
|
func NewKeyCertificate(bytes []byte) (key_certificate *KeyCertificate, remainder []byte, err error) {
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"input_length": len(bytes),
|
|
|
|
}).Debug("Creating new KeyCertificate")
|
|
|
|
|
2024-10-03 21:31:54 -04:00
|
|
|
var certificate Certificate
|
2022-05-09 20:43:24 -04:00
|
|
|
certificate, remainder, err = ReadCertificate(bytes)
|
2024-10-03 21:31:54 -04:00
|
|
|
if err != nil {
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithError(err).Error("Failed to read Certificate")
|
2024-10-03 21:31:54 -04:00
|
|
|
return
|
|
|
|
}
|
2022-04-27 10:48:59 -04:00
|
|
|
if len(bytes) < KEYCERT_MIN_SIZE {
|
|
|
|
err = errors.New("error parsing key certificate: not enough data")
|
2024-10-03 21:31:54 -04:00
|
|
|
remainder = bytes[KEYCERT_MIN_SIZE:]
|
2024-10-18 12:27:42 -04:00
|
|
|
log.WithError(err).Error("KeyCertificate data too short")
|
2024-10-03 21:31:54 -04:00
|
|
|
}
|
|
|
|
key_certificate = &KeyCertificate{
|
|
|
|
Certificate: certificate,
|
|
|
|
}
|
|
|
|
if len(bytes) >= 5 {
|
|
|
|
key_certificate.spkType = Integer(bytes[4:5])
|
2022-04-27 10:48:59 -04:00
|
|
|
}
|
2024-10-03 21:31:54 -04:00
|
|
|
if len(bytes) >= 7 {
|
|
|
|
key_certificate.cpkType = Integer(bytes[6:7])
|
2022-04-27 10:48:59 -04:00
|
|
|
}
|
2024-10-18 12:27:42 -04:00
|
|
|
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"spk_type": key_certificate.spkType.Int(),
|
|
|
|
"cpk_type": key_certificate.cpkType.Int(),
|
|
|
|
"remainder_length": len(remainder),
|
|
|
|
}).Debug("Successfully created new KeyCertificate")
|
|
|
|
|
2022-04-27 10:48:59 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-12 08:31:02 +00:00
|
|
|
// KeyCertificateFromCertificate returns a *KeyCertificate from a *Certificate.
|
2024-10-03 21:31:54 -04:00
|
|
|
func KeyCertificateFromCertificate(certificate Certificate) *KeyCertificate {
|
2024-10-18 12:27:42 -04:00
|
|
|
log.Debug("Creating KeyCertificate from Certificate")
|
2024-10-18 13:22:36 -04:00
|
|
|
// k, _, _ := NewKeyCertificate(certificate.RawBytes())
|
2024-10-18 12:27:42 -04:00
|
|
|
k, _, err := NewKeyCertificate(certificate.RawBytes())
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("Failed to create KeyCertificate from Certificate")
|
|
|
|
} else {
|
|
|
|
log.Debug("Successfully created KeyCertificate from Certificate")
|
|
|
|
}
|
2022-04-27 10:48:59 -04:00
|
|
|
return k
|
|
|
|
}
|