Skip to content

Commit

Permalink
fix encoding of x5c certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst committed Dec 3, 2024
1 parent 39f7cb9 commit 3ddd7e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions uzi_vc_issuer/ura_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/sha1"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"errors"
"fmt"
"github.com/nuts-foundation/go-did/did"
Expand Down Expand Up @@ -172,7 +171,7 @@ func BuildUraVerifiableCredential(chain []*x509.Certificate, signingKey *rsa.Pri
func marshalChain(certificates ...*x509.Certificate) (*cert.Chain, error) {
chainPems := &cert.Chain{}
for _, certificate := range certificates {
err := chainPems.Add(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certificate.Raw}))
err := chainPems.Add([]byte(base64.StdEncoding.EncodeToString(certificate.Raw)))
if err != nil {
return nil, err
}
Expand Down
22 changes: 11 additions & 11 deletions uzi_vc_validator/ura_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/uzi-did-x509-issuer/ca_certs"
"github.com/nuts-foundation/uzi-did-x509-issuer/did_x509"
pem2 "github.com/nuts-foundation/uzi-did-x509-issuer/pem"
"github.com/nuts-foundation/uzi-did-x509-issuer/x509_cert"
)

Expand Down Expand Up @@ -192,16 +191,17 @@ func parseCertificate(chain *cert.Chain) ([]*x509.Certificate, error) {
var certificates []*x509.Certificate
for i := 0; i < chain.Len(); i++ {
bytes, _ := chain.Get(i)
blocks := pem2.ParsePemBlocks(bytes, "CERTIFICATE")
for _, block := range blocks {
found, err := x509.ParseCertificates(block)
if err != nil {
return nil, err
}
for _, c := range found {
if c != nil {
certificates = append(certificates, c)
}
der, err := base64.StdEncoding.DecodeString(string(bytes))
if err != nil {
return nil, err
}
found, err := x509.ParseCertificates(der)
if err != nil {
return nil, err
}
for _, c := range found {
if c != nil {
certificates = append(certificates, c)
}
}
}
Expand Down

0 comments on commit 3ddd7e9

Please sign in to comment.