Skip to content

Commit 9bebfd0

Browse files
fix(core): Fixes protoJSON parse bug on ec rewrap (#1943)
- 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.
1 parent 9438268 commit 9bebfd0

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

docs/grpc/index.html

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol/go/kas/kas.pb.go

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample.tdf

1.49 KB
Binary file not shown.

sdk/tdf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ func createRewrapRequest(_ context.Context, r *Reader) (map[string]*kas.Unsigned
975975
},
976976
SplitId: kao.SplitID,
977977
WrappedKey: key,
978-
EphemeralPublicKey: []byte(kao.EphemeralPublicKey),
978+
EphemeralPublicKey: kao.EphemeralPublicKey,
979979
},
980980
}
981981
if req, ok := kasReqs[kao.KasURL]; ok {

service/kas/access/rewrap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func extractAndConvertV1SRTBody(body []byte) (kaspb.UnsignedRewrapRequest, error
170170
SplitId: kao.SID,
171171
WrappedKey: kao.WrappedKey,
172172
Header: kao.Header,
173-
EphemeralPublicKey: []byte(kao.EphemeralPublicKey),
173+
EphemeralPublicKey: kao.EphemeralPublicKey,
174174
},
175175
},
176176
},
@@ -467,7 +467,7 @@ func (p *Provider) verifyRewrapRequests(ctx context.Context, req *kaspb.Unsigned
467467
ephemeralPubKeyPEM := kao.GetKeyAccessObject().GetEphemeralPublicKey()
468468

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

480480
// Parse the PEM public key
481-
block, _ := pem.Decode(ephemeralPubKeyPEM)
481+
block, _ := pem.Decode([]byte(ephemeralPubKeyPEM))
482482
if block == nil {
483483
return nil, results, fmt.Errorf("failed to decode PEM block")
484484
}

service/kas/kas.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ message KeyAccess {
4848
// header is only used for NanoTDFs
4949
bytes header = 9;
5050

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

5556
message UnsignedRewrapRequest {

0 commit comments

Comments
 (0)