mirror of
https://github.com/versity/versitygw.git
synced 2026-09-24 00:44:23 +00:00
fix: deprecations in JWK and IPA RSA handling
Go 1.26 marks PKCS#1 v1.5 RSA encryption and direct ECDSA public-key coordinate access as deprecated. The IPA code path uses rsa.EncryptPKCS1v15 to wrap an AES session key for vault retrieval, and the OIDC JWKS parser rebuilt EC public keys by setting ecdsa.PublicKey.X and Y directly. This change replaces the deprecated RSA wrap with rsa.EncryptOAEP using SHA-256, which is the standard safe replacement for PKCS#1 v1.5 encryption and preserves the same protocol semantics for the IPA vault exchange. For EC JWKs, it reconstructs the raw uncompressed public point and parses it through ecdsa.ParseUncompressedPublicKey, which is the supported Go API for EC public keys and avoids mutating deprecated fields while preserving the exact mathematical key value. These changes do not alter the wire protocol or trust decisions; they only migrate to the supported stdlib APIs for equivalent behavior.
This commit is contained in:
+2
-1
@@ -19,6 +19,7 @@ import (
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
@@ -168,7 +169,7 @@ func (ipa *IpaIAMService) GetUserAccount(access string) (Account, error) {
|
||||
return account, fmt.Errorf("ipa cannot generate session key: %w", err)
|
||||
}
|
||||
|
||||
encryptedKey, err := rsa.EncryptPKCS1v15(rand.Reader, ipa.kraTransportKey, session_key)
|
||||
encryptedKey, err := rsa.EncryptOAEP(sha256.New(), rand.Reader, ipa.kraTransportKey, session_key, nil)
|
||||
if err != nil {
|
||||
return account, fmt.Errorf("ipa vault secret retrieval: %w", err)
|
||||
}
|
||||
|
||||
@@ -543,11 +543,15 @@ func (k jwk) publicKey() (any, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decode EC y: %w", err)
|
||||
}
|
||||
return &ecdsa.PublicKey{
|
||||
Curve: curve,
|
||||
X: new(big.Int).SetBytes(xb),
|
||||
Y: new(big.Int).SetBytes(yb),
|
||||
}, nil
|
||||
x := new(big.Int).SetBytes(xb)
|
||||
y := new(big.Int).SetBytes(yb)
|
||||
keyBytes := make([]byte, 1+(curve.Params().BitSize+7)/8*2)
|
||||
keyBytes[0] = 0x04
|
||||
xBytes := x.FillBytes(make([]byte, (curve.Params().BitSize+7)/8))
|
||||
yBytes := y.FillBytes(make([]byte, (curve.Params().BitSize+7)/8))
|
||||
copy(keyBytes[1:1+len(xBytes)], xBytes)
|
||||
copy(keyBytes[1+len(xBytes):], yBytes)
|
||||
return ecdsa.ParseUncompressedPublicKey(curve, keyBytes)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported JWK key type %q", k.Kty)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user