Skip to content

Commit

Permalink
fix(core): Fixes protoJSON parse bug on ec rewrap (#1943)
Browse files Browse the repository at this point in the history
- protoJSON encodes/decodes `bytes` types as base64 for us. So good for
the wrapped key (ciphertext value), but bad or at least not right for
PEM encoded string values.
  • Loading branch information
dmihalcik-virtru authored Feb 26, 2025
1 parent 9438268 commit 9bebfd0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions docs/grpc/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions protocol/go/kas/kas.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added sample.tdf
Binary file not shown.
2 changes: 1 addition & 1 deletion sdk/tdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ func createRewrapRequest(_ context.Context, r *Reader) (map[string]*kas.Unsigned
},
SplitId: kao.SplitID,
WrappedKey: key,
EphemeralPublicKey: []byte(kao.EphemeralPublicKey),
EphemeralPublicKey: kao.EphemeralPublicKey,
},
}
if req, ok := kasReqs[kao.KasURL]; ok {
Expand Down
6 changes: 3 additions & 3 deletions service/kas/access/rewrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func extractAndConvertV1SRTBody(body []byte) (kaspb.UnsignedRewrapRequest, error
SplitId: kao.SID,
WrappedKey: kao.WrappedKey,
Header: kao.Header,
EphemeralPublicKey: []byte(kao.EphemeralPublicKey),
EphemeralPublicKey: kao.EphemeralPublicKey,
},
},
},
Expand Down Expand Up @@ -467,7 +467,7 @@ func (p *Provider) verifyRewrapRequests(ctx context.Context, req *kaspb.Unsigned
ephemeralPubKeyPEM := kao.GetKeyAccessObject().GetEphemeralPublicKey()

// Get EC key size and convert to mode
keySize, err := ocrypto.GetECKeySize(ephemeralPubKeyPEM)
keySize, err := ocrypto.GetECKeySize([]byte(ephemeralPubKeyPEM))
if err != nil {
return nil, results, fmt.Errorf("failed to get EC key size: %w", err)
}
Expand All @@ -478,7 +478,7 @@ func (p *Provider) verifyRewrapRequests(ctx context.Context, req *kaspb.Unsigned
}

// Parse the PEM public key
block, _ := pem.Decode(ephemeralPubKeyPEM)
block, _ := pem.Decode([]byte(ephemeralPubKeyPEM))
if block == nil {
return nil, results, fmt.Errorf("failed to decode PEM block")
}
Expand Down
5 changes: 3 additions & 2 deletions service/kas/kas.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ message KeyAccess {
// header is only used for NanoTDFs
bytes header = 9;

// For wrapping with an ECDH derived key, when type=ec-wrapped
bytes ephemeral_public_key = 10;
// For wrapping with an ECDH derived key, when type=ec-wrapped.
// Should be a PEM-encoded PKCS#8 (asn.1) value.
string ephemeral_public_key = 10;
}

message UnsignedRewrapRequest {
Expand Down

0 comments on commit 9bebfd0

Please sign in to comment.