mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
pkcs7: fallback change
This commit is contained in:
parent
0d1fe8c95c
commit
1cf8782870
@ -83,7 +83,7 @@ func fromBase10(base10 string) *big.Int {
|
|||||||
|
|
||||||
type certKeyPair struct {
|
type certKeyPair struct {
|
||||||
Certificate *smx509.Certificate
|
Certificate *smx509.Certificate
|
||||||
PrivateKey crypto.PrivateKey
|
PrivateKey *crypto.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestCertificate(sigAlg x509.SignatureAlgorithm, allCA bool) (certKeyPair, error) {
|
func createTestCertificate(sigAlg x509.SignatureAlgorithm, allCA bool) (certKeyPair, error) {
|
||||||
|
@ -171,7 +171,7 @@ func TestCreateSignedEvnvelopedDataSM(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
privKey := make([]byte, 32)
|
privKey := make([]byte, 32)
|
||||||
sm2Key, ok := (encryptKey.PrivateKey).(*sm2.PrivateKey)
|
sm2Key, ok := (*encryptKey.PrivateKey).(*sm2.PrivateKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("should be sm2 private key")
|
t.Fatal("should be sm2 private key")
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ func TestCreateSignedEvnvelopedDataSM(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err = saed.AddSigner(rootCert.Certificate, rootCert.PrivateKey)
|
err = saed.AddSigner(rootCert.Certificate, *rootCert.PrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ func TestCreateSignedEvnvelopedDataSM(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
encKeyBytes, err := p7Data.DecryptAndVerify(recipient.Certificate, recipient.PrivateKey, func() error {
|
encKeyBytes, err := p7Data.DecryptAndVerify(recipient.Certificate, *recipient.PrivateKey, func() error {
|
||||||
return p7Data.Verify()
|
return p7Data.Verify()
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -234,7 +234,7 @@ func TestCreateSignedEvnvelopedData(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
privKey := make([]byte, 32)
|
privKey := make([]byte, 32)
|
||||||
ecdsaKey, ok := (encryptKey.PrivateKey).(*ecdsa.PrivateKey)
|
ecdsaKey, ok := (*encryptKey.PrivateKey).(*ecdsa.PrivateKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("should be ecdsa private key")
|
t.Fatal("should be ecdsa private key")
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ func TestCreateSignedEvnvelopedData(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
saed.SetDigestAlgorithm(OIDDigestAlgorithmSHA256)
|
saed.SetDigestAlgorithm(OIDDigestAlgorithmSHA256)
|
||||||
err = saed.AddSigner(rootCert.Certificate, rootCert.PrivateKey)
|
err = saed.AddSigner(rootCert.Certificate, *rootCert.PrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ func TestCreateSignedEvnvelopedData(t *testing.T) {
|
|||||||
t.Errorf("Recipient issuer name does not match.\n\tExpected:%x\n\tActual:%x", recipient.Certificate.RawIssuer, recipients[0].RawIssuer)
|
t.Errorf("Recipient issuer name does not match.\n\tExpected:%x\n\tActual:%x", recipient.Certificate.RawIssuer, recipients[0].RawIssuer)
|
||||||
}
|
}
|
||||||
|
|
||||||
encKeyBytes, err := p7Data.DecryptAndVerify(recipient.Certificate, recipient.PrivateKey, func() error {
|
encKeyBytes, err := p7Data.DecryptAndVerify(recipient.Certificate, *recipient.PrivateKey, func() error {
|
||||||
return p7Data.Verify()
|
return p7Data.Verify()
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +51,7 @@ func testSign(t *testing.T, isSM bool, content []byte, sigalgs []x509.SignatureA
|
|||||||
signerDigest, _ := getDigestOIDForSignatureAlgorithm(sigalgsigner)
|
signerDigest, _ := getDigestOIDForSignatureAlgorithm(sigalgsigner)
|
||||||
toBeSigned.SetDigestAlgorithm(signerDigest)
|
toBeSigned.SetDigestAlgorithm(signerDigest)
|
||||||
|
|
||||||
if err := toBeSigned.AddSignerChain(signerCert.Certificate, signerCert.PrivateKey, parents, SignerInfoConfig{}); err != nil {
|
if err := toBeSigned.AddSignerChain(signerCert.Certificate, *signerCert.PrivateKey, parents, SignerInfoConfig{}); err != nil {
|
||||||
t.Fatalf("test %s/%s/%s: cannot add signer: %s", sigalgroot, sigalginter, sigalgsigner, err)
|
t.Fatalf("test %s/%s/%s: cannot add signer: %s", sigalgroot, sigalginter, sigalgsigner, err)
|
||||||
}
|
}
|
||||||
if testDetach {
|
if testDetach {
|
||||||
@ -152,7 +152,7 @@ func TestUnmarshalSignedAttribute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
oidTest := asn1.ObjectIdentifier{2, 3, 4, 5, 6, 7}
|
oidTest := asn1.ObjectIdentifier{2, 3, 4, 5, 6, 7}
|
||||||
testValue := "TestValue"
|
testValue := "TestValue"
|
||||||
if err := toBeSigned.AddSigner(cert.Certificate, cert.PrivateKey, SignerInfoConfig{
|
if err := toBeSigned.AddSigner(cert.Certificate, *cert.PrivateKey, SignerInfoConfig{
|
||||||
ExtraSignedAttributes: []Attribute{{Type: oidTest, Value: testValue}},
|
ExtraSignedAttributes: []Attribute{{Type: oidTest, Value: testValue}},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatalf("Cannot add signer: %s", err)
|
t.Fatalf("Cannot add signer: %s", err)
|
||||||
@ -190,7 +190,7 @@ func TestSkipCertificates(t *testing.T) {
|
|||||||
t.Fatalf("Cannot initialize signed data: %s", err)
|
t.Fatalf("Cannot initialize signed data: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := toBeSigned.AddSigner(cert.Certificate, cert.PrivateKey, SignerInfoConfig{}); err != nil {
|
if err := toBeSigned.AddSigner(cert.Certificate, *cert.PrivateKey, SignerInfoConfig{}); err != nil {
|
||||||
t.Fatalf("Cannot add signer: %s", err)
|
t.Fatalf("Cannot add signer: %s", err)
|
||||||
}
|
}
|
||||||
signed, err := toBeSigned.Finish()
|
signed, err := toBeSigned.Finish()
|
||||||
@ -209,7 +209,7 @@ func TestSkipCertificates(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot initialize signed data: %s", err)
|
t.Fatalf("Cannot initialize signed data: %s", err)
|
||||||
}
|
}
|
||||||
if err := toBeSigned2.AddSigner(cert.Certificate, cert.PrivateKey, SignerInfoConfig{SkipCertificates: true}); err != nil {
|
if err := toBeSigned2.AddSigner(cert.Certificate, *cert.PrivateKey, SignerInfoConfig{SkipCertificates: true}); err != nil {
|
||||||
t.Fatalf("Cannot add signer: %s", err)
|
t.Fatalf("Cannot add signer: %s", err)
|
||||||
}
|
}
|
||||||
signed, err = toBeSigned2.Finish()
|
signed, err = toBeSigned2.Finish()
|
||||||
@ -313,7 +313,7 @@ func TestSignWithoutAttr(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot initialize signed data: %s", err)
|
t.Fatalf("Cannot initialize signed data: %s", err)
|
||||||
}
|
}
|
||||||
if err := toBeSigned.SignWithoutAttr(cert.Certificate, cert.PrivateKey, SignerInfoConfig{SkipCertificates: sigalg.skipCert}); err != nil {
|
if err := toBeSigned.SignWithoutAttr(cert.Certificate, *cert.PrivateKey, SignerInfoConfig{SkipCertificates: sigalg.skipCert}); err != nil {
|
||||||
t.Fatalf("Cannot add signer: %s", err)
|
t.Fatalf("Cannot add signer: %s", err)
|
||||||
}
|
}
|
||||||
signed, err := toBeSigned.Finish()
|
signed, err := toBeSigned.Finish()
|
||||||
|
@ -527,7 +527,7 @@ but that's not what ships are built for.
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var derKey []byte
|
var derKey []byte
|
||||||
priv := signerCert.PrivateKey
|
priv := *signerCert.PrivateKey
|
||||||
switch priv := priv.(type) {
|
switch priv := priv.(type) {
|
||||||
case *rsa.PrivateKey:
|
case *rsa.PrivateKey:
|
||||||
derKey = x509.MarshalPKCS1PrivateKey(priv)
|
derKey = x509.MarshalPKCS1PrivateKey(priv)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user