Skip to content

Commit 196ab2b

Browse files
UgnineSirdisGazizonoki
authored andcommitted
Moved commit "Fix HMAC secret key loading for OAuth 2.0 token exchange config" from ydb repo
1 parent 5970eb0 commit 196ab2b

File tree

6 files changed

+133
-21
lines changed

6 files changed

+133
-21
lines changed

src/client/types/credentials/oauth2_token_exchange/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ target_link_libraries(client-ydb_types-credentials-oauth2
99
http-simple
1010
json
1111
retry
12+
string_utils-base64
1213
uri
1314
client-ydb_types-credentials
1415
client-ydb_types

src/client/types/credentials/oauth2_token_exchange/from_file.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/jwt_token_source.h>
44

55
#include <library/cpp/json/json_reader.h>
6+
#include <src/library/string_utils/base64/base64.h>
67

7-
#include <util/generic/map.h>
88
#include <util/stream/file.h>
99
#include <util/string/builder.h>
1010
#include <util/string/cast.h>
@@ -32,13 +32,45 @@ void ApplyAsymmetricAlg(TJwtTokenSourceParams* params, const std::string& privat
3232
params->SigningAlgorithm<TAlg>(std::string{}, privateKey);
3333
}
3434

35+
size_t Base64OutputLen(std::string_view input) {
36+
while (!input.empty() && (input.back() == '=' || input.back() == ',')) { // padding
37+
input.remove_suffix(1);
38+
}
39+
const size_t inputLen = input.size();
40+
const size_t tailEncoded = inputLen % 4;
41+
if (tailEncoded == 1) {
42+
throw std::runtime_error(TStringBuilder() << "invalid Base64 encoded data size: " << input.size());
43+
}
44+
const size_t mainSize = (inputLen / 4) * 3;
45+
size_t tailSize = 0;
46+
switch (tailEncoded) {
47+
case 2: // 12 bit => 1 byte
48+
tailSize = 1;
49+
break;
50+
case 3: // 18 bits -> 2 bytes
51+
tailSize = 2;
52+
break;
53+
}
54+
return mainSize + tailSize;
55+
}
56+
3557
template <class TAlg>
3658
void ApplyHmacAlg(TJwtTokenSourceParams* params, const std::string& key) {
59+
// HMAC keys are encoded in base64 encoding
60+
const size_t base64OutputSize = Base64OutputLen(key); // throws
61+
std::string binaryKey;
62+
binaryKey.resize(Base64DecodeBufSize(key.size()));
63+
// allows strings without padding
64+
const size_t decodedBytes = Base64DecodeUneven(const_cast<char*>(binaryKey.data()), key);
65+
if (decodedBytes != base64OutputSize) {
66+
throw std::runtime_error("failed to decode HMAC secret from Base64");
67+
}
68+
binaryKey.resize(decodedBytes);
3769
// Alg with first param as key
38-
params->SigningAlgorithm<TAlg>(key);
70+
params->SigningAlgorithm<TAlg>(binaryKey);
3971
}
4072

41-
const TMap<std::string, void(*)(TJwtTokenSourceParams*, const std::string& privateKey), TLessNoCase> JwtAlgorithmsFactory = {
73+
const std::map<std::string, void(*)(TJwtTokenSourceParams*, const std::string& privateKey), TLessNoCase> JwtAlgorithmsFactory = {
4274
{"RS256", &ApplyAsymmetricAlg<jwt::algorithm::rs256>},
4375
{"RS384", &ApplyAsymmetricAlg<jwt::algorithm::rs384>},
4476
{"RS512", &ApplyAsymmetricAlg<jwt::algorithm::rs512>},

tests/unit/client/oauth2_token_exchange/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_ydb_test(NAME client-oauth2_ut
77
cpp-testing-unittest_main
88
http-server
99
json
10+
string_utils-base64
1011
client-ydb_types-credentials-oauth2
1112
LABELS
1213
unit

tests/unit/client/oauth2_token_exchange/credentials_ut.cpp

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/from_file.h>
33
#include "jwt_check_helper.h"
44

5+
#include <src/library/string_utils/base64/base64.h>
6+
57
#include <library/cpp/cgiparam/cgiparam.h>
68
#include <library/cpp/http/misc/parsed_request.h>
79
#include <library/cpp/http/server/http.h>
@@ -16,8 +18,11 @@
1618

1719
using namespace NYdb;
1820

19-
extern const std::string TestPrivateKeyContent;
20-
extern const std::string TestPublicKeyContent;
21+
extern const std::string TestRSAPrivateKeyContent;
22+
extern const std::string TestRSAPublicKeyContent;
23+
extern const std::string TestECPrivateKeyContent;
24+
extern const std::string TestECPublicKeyContent;
25+
extern const std::string TestHMACSecretKeyBase64Content;
2126

2227
class TTestTokenExchangeServer: public THttpServer::ICallBack {
2328
public:
@@ -33,7 +38,7 @@ class TTestTokenExchangeServer: public THttpServer::ICallBack {
3338
std::optional<TJwtCheck> ActorJwtCheck;
3439

3540
void Check() {
36-
UNIT_ASSERT(InputParams || !ExpectRequest);
41+
UNIT_ASSERT_C(InputParams || !ExpectRequest, "Request error: " << Error);
3742
if (InputParams) {
3843
if (SubjectJwtCheck || ActorJwtCheck) {
3944
TCgiParameters inputParamsCopy = *InputParams;
@@ -976,7 +981,7 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
976981
.Subject("test_sub")
977982
.Audience("test_aud")
978983
.Id("test_jti")
979-
.Alg<jwt::algorithm::rs384>(TestPublicKeyContent);
984+
.Alg<jwt::algorithm::rs384>(TestRSAPublicKeyContent);
980985
server.Check.ActorJwtCheck.emplace()
981986
.AppendAudience("a1")
982987
.AppendAudience("a2");
@@ -993,7 +998,7 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
993998
.Field("aud", "test_aud")
994999
.Field("jti", "test_jti")
9951000
.Field("alg", "rs384")
996-
.Field("private-key", TestPrivateKeyContent)
1001+
.Field("private-key", TestRSAPrivateKeyContent)
9971002
.Field("unknown", "unknown value")
9981003
.Build()
9991004
.SubMap("actor-credentials")
@@ -1003,7 +1008,33 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
10031008
.Value("a2")
10041009
.Build()
10051010
.Field("alg", "RS256")
1006-
.Field("private-key", TestPrivateKeyContent)
1011+
.Field("private-key", TestRSAPrivateKeyContent)
1012+
.Build()
1013+
.Build(),
1014+
"Bearer received_token"
1015+
);
1016+
1017+
// Other signing methods
1018+
server.Check.SubjectJwtCheck.emplace()
1019+
.Id("jti")
1020+
.Alg<jwt::algorithm::hs384>(Base64Decode(TestHMACSecretKeyBase64Content));
1021+
server.Check.ActorJwtCheck.emplace()
1022+
.Alg<jwt::algorithm::es256>(TestECPublicKeyContent)
1023+
.Issuer("iss");
1024+
server.RunFromConfig(
1025+
TTestConfigFile()
1026+
.Field("token-endpoint", server.GetEndpoint())
1027+
.SubMap("subject-credentials")
1028+
.Field("type", "jwt")
1029+
.Field("jti", "jti")
1030+
.Field("alg", "HS384")
1031+
.Field("private-key", TestHMACSecretKeyBase64Content)
1032+
.Build()
1033+
.SubMap("actor-credentials")
1034+
.Field("type", "JWT")
1035+
.Field("alg", "ES256")
1036+
.Field("private-key", TestECPrivateKeyContent)
1037+
.Field("iss", "iss")
10071038
.Build()
10081039
.Build(),
10091040
"Bearer received_token"
@@ -1089,7 +1120,7 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
10891120
.Field("token-endpoint", server.GetEndpoint())
10901121
.SubMap("subject-credentials")
10911122
.Field("type", "jwt")
1092-
.Field("private-key", TestPrivateKeyContent)
1123+
.Field("private-key", TestRSAPrivateKeyContent)
10931124
.Build()
10941125
.Build()
10951126
);
@@ -1112,7 +1143,7 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
11121143
.SubMap("subject-credentials")
11131144
.Field("type", "jwt")
11141145
.Field("alg", "rs256")
1115-
.Field("private-key", TestPrivateKeyContent)
1146+
.Field("private-key", TestRSAPrivateKeyContent)
11161147
.Field("ttl", "-1s")
11171148
.Build()
11181149
.Build()
@@ -1125,7 +1156,7 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
11251156
.SubMap("subject-credentials")
11261157
.Field("type", "jwt")
11271158
.Field("alg", "algorithm")
1128-
.Field("private-key", TestPrivateKeyContent)
1159+
.Field("private-key", TestRSAPrivateKeyContent)
11291160
.Build()
11301161
.Build()
11311162
);
@@ -1145,6 +1176,50 @@ Y_UNIT_TEST_SUITE(TestTokenExchange) {
11451176
.Build()
11461177
);
11471178

1179+
server.Check.ExpectedErrorPart = "failed to decode HMAC secret from Base64";
1180+
server.RunFromConfig(
1181+
TTestConfigFile()
1182+
.Field("token-endpoint", server.GetEndpoint())
1183+
.SubMap("subject-credentials")
1184+
.Field("type", "jwt")
1185+
.Field("alg", "hs256")
1186+
.Field("private-key", "\n<not a base64>\n")
1187+
.Build()
1188+
.Build()
1189+
);
1190+
1191+
#ifdef YDB_SDK_USE_NEW_JWT
1192+
server.Check.ExpectedErrorPart = "invalid key size";
1193+
#else
1194+
server.Check.ExpectedErrorPart = "failed to load private key";
1195+
#endif
1196+
server.RunFromConfig(
1197+
TTestConfigFile()
1198+
.Field("token-endpoint", server.GetEndpoint())
1199+
.SubMap("subject-credentials")
1200+
.Field("type", "jwt")
1201+
.Field("alg", "es256")
1202+
.Field("private-key", TestRSAPrivateKeyContent) // Need EC key
1203+
.Build()
1204+
.Build()
1205+
);
1206+
1207+
#ifdef YDB_SDK_USE_NEW_JWT
1208+
server.Check.ExpectedErrorPart = "failed to load key";
1209+
#else
1210+
server.Check.ExpectedErrorPart = "failed to load private key";
1211+
#endif
1212+
server.RunFromConfig(
1213+
TTestConfigFile()
1214+
.Field("token-endpoint", server.GetEndpoint())
1215+
.SubMap("subject-credentials")
1216+
.Field("type", "jwt")
1217+
.Field("alg", "ps512")
1218+
.Field("private-key", TestHMACSecretKeyBase64Content) // Need RSA key
1219+
.Build()
1220+
.Build()
1221+
);
1222+
11481223
server.Check.ExpectedErrorPart = "Not a map";
11491224
server.RunFromConfig(
11501225
TTestConfigFile()

tests/unit/client/oauth2_token_exchange/jwt_check_helper.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#include <jwt-cpp/jwt.h>
55

6-
extern const std::string TestPrivateKeyContent;
7-
extern const std::string TestPublicKeyContent;
6+
extern const std::string TestRSAPrivateKeyContent;
7+
extern const std::string TestRSAPublicKeyContent;
88

99
struct TJwtCheck {
1010
using TSelf = TJwtCheck;
@@ -45,10 +45,10 @@ struct TJwtCheck {
4545

4646
template <class TAlg>
4747
TSelf& Alg(const std::string& publicKey) {
48-
Alg_.Reset(new TAlgCheck<TAlg>(publicKey));
48+
Alg_.reset(new TAlgCheck<TAlg>(publicKey));
4949
return *this;
5050
}
51-
THolder<IAlgCheck> Alg_ = MakeHolder<TAlgCheck<jwt::algorithm::rs256>>(TestPublicKeyContent);
51+
std::unique_ptr<IAlgCheck> Alg_ = std::make_unique<TAlgCheck<jwt::algorithm::rs256>>(TestRSAPublicKeyContent);
5252

5353
FLUENT_SETTING_OPTIONAL(std::string, KeyId);
5454

tests/unit/client/oauth2_token_exchange/jwt_token_source_ut.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77

88
using namespace NYdb;
99

10-
extern const std::string TestPrivateKeyContent = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC75/JS3rMcLJxv\nFgpOzF5+2gH+Yig3RE2MTl9uwC0BZKAv6foYr7xywQyWIK+W1cBhz8R4LfFmZo2j\nM0aCvdRmNBdW0EDSTnHLxCsFhoQWLVq+bI5f5jzkcoiioUtaEpADPqwgVULVtN/n\nnPJiZ6/dU30C3jmR6+LUgEntUtWt3eq3xQIn5lG3zC1klBY/HxtfH5Hu8xBvwRQT\nJnh3UpPLj8XwSmriDgdrhR7o6umWyVuGrMKlLHmeivlfzjYtfzO1MOIMG8t2/zxG\nR+xb4Vwks73sH1KruH/0/JMXU97npwpe+Um+uXhpldPygGErEia7abyZB2gMpXqr\nWYKMo02NAgMBAAECggEAO0BpC5OYw/4XN/optu4/r91bupTGHKNHlsIR2rDzoBhU\nYLd1evpTQJY6O07EP5pYZx9mUwUdtU4KRJeDGO/1/WJYp7HUdtxwirHpZP0lQn77\nuccuX/QQaHLrPekBgz4ONk+5ZBqukAfQgM7fKYOLk41jgpeDbM2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rCOp79TNnNIsh7\n-----END PRIVATE KEY-----\n";
11-
extern const std::string TestPublicKeyContent = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu+fyUt6zHCycbxYKTsxe\nftoB/mIoN0RNjE5fbsAtAWSgL+n6GK+8csEMliCvltXAYc/EeC3xZmaNozNGgr3U\nZjQXVtBA0k5xy8QrBYaEFi1avmyOX+Y85HKIoqFLWhKQAz6sIFVC1bTf55zyYmev\n3VN9At45kevi1IBJ7VLVrd3qt8UCJ+ZRt8wtZJQWPx8bXx+R7vMQb8EUEyZ4d1KT\ny4/F8Epq4g4Ha4Ue6OrplslbhqzCpSx5nor5X842LX8ztTDiDBvLdv88RkfsW+Fc\nJLO97B9Sq7h/9PyTF1Pe56cKXvlJvrl4aZXT8oBhKxImu2m8mQdoDKV6q1mCjKNN\njQIDAQAB\n-----END PUBLIC KEY-----\n";
10+
extern const std::string TestRSAPrivateKeyContent = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC75/JS3rMcLJxv\nFgpOzF5+2gH+Yig3RE2MTl9uwC0BZKAv6foYr7xywQyWIK+W1cBhz8R4LfFmZo2j\nM0aCvdRmNBdW0EDSTnHLxCsFhoQWLVq+bI5f5jzkcoiioUtaEpADPqwgVULVtN/n\nnPJiZ6/dU30C3jmR6+LUgEntUtWt3eq3xQIn5lG3zC1klBY/HxtfH5Hu8xBvwRQT\nJnh3UpPLj8XwSmriDgdrhR7o6umWyVuGrMKlLHmeivlfzjYtfzO1MOIMG8t2/zxG\nR+xb4Vwks73sH1KruH/0/JMXU97npwpe+Um+uXhpldPygGErEia7abyZB2gMpXqr\nWYKMo02NAgMBAAECggEAO0BpC5OYw/4XN/optu4/r91bupTGHKNHlsIR2rDzoBhU\nYLd1evpTQJY6O07EP5pYZx9mUwUdtU4KRJeDGO/1/WJYp7HUdtxwirHpZP0lQn77\n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Gg+CS397aWu4cy+mTI+MNfBgeDAIVBeJOJXLlX\nhL8bFAuNNVrCOp79TNnNIsh7\n-----END PRIVATE KEY-----\n";
11+
extern const std::string TestRSAPublicKeyContent = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu+fyUt6zHCycbxYKTsxe\nftoB/mIoN0RNjE5fbsAtAWSgL+n6GK+8csEMliCvltXAYc/EeC3xZmaNozNGgr3U\nZjQXVtBA0k5xy8QrBYaEFi1avmyOX+Y85HKIoqFLWhKQAz6sIFVC1bTf55zyYmev\n3VN9At45kevi1IBJ7VLVrd3qt8UCJ+ZRt8wtZJQWPx8bXx+R7vMQb8EUEyZ4d1KT\ny4/F8Epq4g4Ha4Ue6OrplslbhqzCpSx5nor5X842LX8ztTDiDBvLdv88RkfsW+Fc\nJLO97B9Sq7h/9PyTF1Pe56cKXvlJvrl4aZXT8oBhKxImu2m8mQdoDKV6q1mCjKNN\njQIDAQAB\n-----END PUBLIC KEY-----\n";
12+
extern const std::string TestECPrivateKeyContent = "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIB6fv25gf7P/7fkjW/2kcKICUhHeOygkFeUJ/ylyU3hloAoGCCqGSM49\nAwEHoUQDQgAEvkKy92hpLiT0GEpzFkYBEWWnkAGTTA6141H0oInA9X30eS0RObAa\nmVY8yD39NI7Nj03hBxEa4Z0tOhrq9cW8eg==\n-----END EC PRIVATE KEY-----\n";
13+
extern const std::string TestECPublicKeyContent = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEvkKy92hpLiT0GEpzFkYBEWWnkAGT\nTA6141H0oInA9X30eS0RObAamVY8yD39NI7Nj03hBxEa4Z0tOhrq9cW8eg==\n-----END PUBLIC KEY-----\n";
14+
extern const std::string TestHMACSecretKeyBase64Content = "VGhlIHdvcmxkIGhhcyBjaGFuZ2VkLgpJIHNlZSBpdCBpbiB0aGUgd2F0ZXIuCkkgZmVlbCBpdCBpbiB0aGUgRWFydGguCkkgc21lbGwgaXQgaW4gdGhlIGFpci4KTXVjaCB0aGF0IG9uY2Ugd2FzIGlzIGxvc3QsCkZvciBub25lIG5vdyBsaXZlIHdobyByZW1lbWJlciBpdC4K";
1215

1316
Y_UNIT_TEST_SUITE(JwtTokenSourceTest) {
1417
Y_UNIT_TEST(Encodes) {
1518
auto source = CreateJwtTokenSource(
1619
TJwtTokenSourceParams()
1720
.KeyId("test_key_id")
18-
.SigningAlgorithm<jwt::algorithm::rs256>("", TestPrivateKeyContent)
21+
.SigningAlgorithm<jwt::algorithm::rs256>("", TestRSAPrivateKeyContent)
1922
.Issuer("test_issuer")
2023
.Subject("test_subject")
2124
.Audience("test_audience")
@@ -45,13 +48,13 @@ Y_UNIT_TEST_SUITE(JwtTokenSourceTest) {
4548
UNIT_ASSERT_EXCEPTION_CONTAINS(CreateJwtTokenSource(
4649
TJwtTokenSourceParams()
4750
.KeyId("test_key_id")
48-
.SigningAlgorithm<jwt::algorithm::rs256>("", TestPrivateKeyContent)
51+
.SigningAlgorithm<jwt::algorithm::rs256>("", TestRSAPrivateKeyContent)
4952
.TokenTtl(TDuration::Zero())
5053
), std::invalid_argument, "token TTL must be positive");
5154

5255
UNIT_ASSERT_EXCEPTION_CONTAINS(CreateJwtTokenSource(
5356
TJwtTokenSourceParams()
54-
.SigningAlgorithm<jwt::algorithm::rs256>("", TestPrivateKeyContent)
57+
.SigningAlgorithm<jwt::algorithm::rs256>("", TestRSAPrivateKeyContent)
5558
.AppendAudience("aud")
5659
.AppendAudience("aud2")
5760
.AppendAudience("")

0 commit comments

Comments
 (0)