diff options
author | 2022-11-30 23:13:13 +0100 | |
---|---|---|
committer | 2022-11-30 23:13:13 +0100 | |
commit | 5a0e418281c05f069c7b70bfa3132b258740ece6 (patch) | |
tree | a1b21e7cc961fb969f5bd5f31970c9f989ba55bd /internal | |
parent | [docs] Add AppArmor profile for Debian and Ubuntu installations (#1183) (diff) | |
download | gotosocial-5a0e418281c05f069c7b70bfa3132b258740ece6.tar.xz |
[feature] Support PKCS1 "RSA PUBLIC KEY" pem block type (#1179)
* ap: add support for PKCS1 "RSA PUBLIC KEY" pem block type
Signed-off-by: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
* ap: report no PEM data or unknown pem block type
Signed-off-by: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
Signed-off-by: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
Diffstat (limited to 'internal')
-rw-r--r-- | internal/ap/extract.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/internal/ap/extract.go b/internal/ap/extract.go index a7a46e51c..74bc94f18 100644 --- a/internal/ap/extract.go +++ b/internal/ap/extract.go @@ -22,6 +22,7 @@ package ap import ( + "crypto" "crypto/rsa" "crypto/x509" "encoding/pem" @@ -318,18 +319,24 @@ func ExtractPublicKeyForOwner(i WithPublicKey, forOwner *url.URL) (*rsa.PublicKe } block, _ := pem.Decode([]byte(pkeyPem)) - if block == nil || block.Type != "PUBLIC KEY" { - return nil, nil, errors.New("could not decode publicKeyPem to PUBLIC KEY pem block type") + if block == nil { + return nil, nil, errors.New("could not decode publicKeyPem: no PEM data") + } + var p crypto.PublicKey + switch block.Type { + case "PUBLIC KEY": + p, err = x509.ParsePKIXPublicKey(block.Bytes) + case "RSA PUBLIC KEY": + p, err = x509.ParsePKCS1PublicKey(block.Bytes) + default: + return nil, nil, fmt.Errorf("could not parse public key: unknown block type: %q", block.Type) } - - p, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { return nil, nil, fmt.Errorf("could not parse public key from block bytes: %s", err) } if p == nil { return nil, nil, errors.New("returned public key was empty") } - if publicKey, ok := p.(*rsa.PublicKey); ok { return publicKey, pkeyID, nil } |