1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16
17 #include "tink/jwt/jwt_signature_config.h"
18
19 #include "absl/memory/memory.h"
20 #include "tink/config/config_util.h"
21 #include "tink/config/tink_fips.h"
22 #include "tink/jwt/internal/jwt_ecdsa_sign_key_manager.h"
23 #include "tink/jwt/internal/jwt_ecdsa_verify_key_manager.h"
24 #include "tink/jwt/internal/jwt_public_key_sign_wrapper.h"
25 #include "tink/jwt/internal/jwt_public_key_verify_wrapper.h"
26 #include "tink/jwt/internal/jwt_rsa_ssa_pkcs1_sign_key_manager.h"
27 #include "tink/jwt/internal/jwt_rsa_ssa_pkcs1_verify_key_manager.h"
28 #include "tink/jwt/internal/jwt_rsa_ssa_pss_sign_key_manager.h"
29 #include "tink/jwt/internal/jwt_rsa_ssa_pss_verify_key_manager.h"
30 #include "tink/registry.h"
31 #include "tink/util/status.h"
32 #include "proto/config.pb.h"
33
34 namespace crypto {
35 namespace tink {
36
37 // static
JwtSignatureRegister()38 util::Status JwtSignatureRegister() {
39 // Register primitive wrappers.
40 auto status = Registry::RegisterPrimitiveWrapper(
41 absl::make_unique<jwt_internal::JwtPublicKeySignWrapper>());
42 if (!status.ok()) return status;
43 status = Registry::RegisterPrimitiveWrapper(
44 absl::make_unique<jwt_internal::JwtPublicKeyVerifyWrapper>());
45 if (!status.ok()) return status;
46
47 // Register key managers which utilize FIPS validated BoringCrypto
48 // implementations.
49 // ECDSA
50 status = Registry::RegisterAsymmetricKeyManagers(
51 absl::make_unique<jwt_internal::JwtEcdsaSignKeyManager>(),
52 absl::make_unique<jwt_internal::JwtEcdsaVerifyKeyManager>(), true);
53 if (!status.ok()) return status;
54 // RSA SSA PKCS1
55 status = Registry::RegisterAsymmetricKeyManagers(
56 absl::make_unique<jwt_internal::JwtRsaSsaPkcs1SignKeyManager>(),
57 absl::make_unique<jwt_internal::JwtRsaSsaPkcs1VerifyKeyManager>(), true);
58 if (!status.ok()) return status;
59 // RSA SSA PSS
60 status = Registry::RegisterAsymmetricKeyManagers(
61 absl::make_unique<jwt_internal::JwtRsaSsaPssSignKeyManager>(),
62 absl::make_unique<jwt_internal::JwtRsaSsaPssVerifyKeyManager>(), true);
63 if (!status.ok()) return status;
64
65 if (IsFipsModeEnabled()) {
66 return util::OkStatus();
67 }
68
69 // There are currently no non-FIPS key managers.
70
71 return util::OkStatus();
72 }
73
74 } // namespace tink
75 } // namespace crypto
76