Skip to content

Commit 37e43ec

Browse files
feat: create SecurityContext class and add signing alg verification to the auth interceptor
1 parent 20d6244 commit 37e43ec

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

Tokenization/backend/wrapper/src/client/ConnectionManager/Interceptors/grpc.auth.interceptor.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,17 @@ export const gRPCAuthInterceptor = async (
139139
pub
140140
);
141141

142-
// Optional: Additional check to ensure correct signing algorithm was used
143-
// if (protectedHeader.alg !== "EdDSA" && protectedHeader.alg !== "Ed25519") {
144-
// throw new Error("JWS signed with an unexpected algorithm.");
145-
// }
142+
// Additional check to ensure correct signing algorithm was used
143+
if (protectedHeader.alg !== "EdDSA" && protectedHeader.alg !== "Ed25519") {
144+
const error = {
145+
name: "AuthenticationError",
146+
message: "Incorrect signing algorithm for JWS.",
147+
code: grpc.status.UNAUTHENTICATED,
148+
};
149+
150+
callback(error, null);
151+
return { isAuthenticated: false, conn };
152+
}
146153

147154
// Decode and parse the JWT payload
148155
const payloadString = new TextDecoder().decode(jwtPayload);
@@ -188,7 +195,7 @@ export const gRPCAuthInterceptor = async (
188195

189196
// Authentication and Authorization successful
190197
// Update Connection state with SN and status
191-
conn.handleSuccessfulAuth(payload as any);
198+
conn.handleSuccessfulAuth(payload);
192199
return { isAuthenticated: true, conn };
193200
};
194201

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license
3+
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
4+
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
5+
* All rights not expressly granted are reserved.
6+
*
7+
* This software is distributed under the terms of the GNU General Public
8+
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
9+
*
10+
* In applying this license CERN does not waive the privileges and immunities
11+
* granted to it by virtue of its status as an Intergovernmental Organization
12+
* or submit itself to any jurisdiction.
13+
*/
14+
15+
/**
16+
* @description Stores every keys and certificates needed for gRPC mTLS communication and token verifications (JWE/JWS)
17+
*/
18+
export class SecurityContext {
19+
// mTLS keys (RSA)
20+
public readonly caCert: Buffer;
21+
public readonly clientSenderCert: Buffer;
22+
public readonly clientListenerCert: Buffer;
23+
public readonly clientPublicKey: Buffer;
24+
// RSA Private Key (PKCS8) for JWE decryption
25+
public readonly clientPrivateKey: Buffer;
26+
27+
// Public Ed25519 key for JWS verification
28+
public static readonly JWS_PUBLIC_KEY =
29+
"VqkcxlpJYVZI/SxgWH/VqVNeKhMGIbUfHn0okzdGs2E=";
30+
31+
constructor(
32+
caCert: Buffer,
33+
clientSenderCert: Buffer,
34+
clientListenerCert: Buffer,
35+
clientPrivateKey: Buffer,
36+
clientPublicKey: Buffer
37+
) {
38+
this.caCert = caCert;
39+
this.clientSenderCert = clientSenderCert;
40+
this.clientListenerCert = clientListenerCert;
41+
this.clientPrivateKey = clientPrivateKey;
42+
this.clientPublicKey = clientPublicKey;
43+
}
44+
}

0 commit comments

Comments
 (0)