-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose la clé publique de l'application
- Loading branch information
Showing
8 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const crypto = require('crypto'); | ||
|
||
const cleHachage = (chaine) => crypto.createHash('md5').update(chaine).digest('hex'); | ||
|
||
module.exports = { | ||
cleHachage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const express = require('express'); | ||
|
||
const routesAuth = (config) => { | ||
const { | ||
adaptateurChiffrement, | ||
adaptateurEnvironnement, | ||
} = config; | ||
|
||
const routes = express.Router(); | ||
|
||
routes.get('/cles_publiques', (_requete, reponse) => { | ||
const { kty, n, e } = adaptateurEnvironnement.clePriveeJWK(); | ||
const idClePublique = adaptateurChiffrement.cleHachage(n); | ||
|
||
const clePubliqueDansJWKSet = { | ||
keys: [{ | ||
kid: idClePublique, | ||
use: 'enc', | ||
kty, | ||
e, | ||
n, | ||
}], | ||
}; | ||
|
||
reponse.set('Content-Type', 'application/json'); | ||
reponse.status(200) | ||
.send(clePubliqueDansJWKSet); | ||
}); | ||
|
||
return routes; | ||
}; | ||
|
||
module.exports = routesAuth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const axios = require('axios'); | ||
|
||
const { leveErreur } = require('./utils'); | ||
const serveurTest = require('./serveurTest'); | ||
|
||
describe('Le serveur des routes `/auth`', () => { | ||
const serveur = serveurTest(); | ||
let port; | ||
|
||
beforeEach((suite) => serveur.initialise(() => { | ||
port = serveur.port(); | ||
suite(); | ||
})); | ||
|
||
afterEach((suite) => serveur.arrete(suite)); | ||
|
||
describe('sur GET /auth/cles_publiques', () => { | ||
it('retourne les clés de chiffrement au format JSON Web Key Set', () => { | ||
serveur.adaptateurEnvironnement().clePriveeJWK = () => ({ | ||
e: 'AQAB', | ||
n: '503as-2qay5...', | ||
kty: 'RSA', | ||
}); | ||
serveur.adaptateurChiffrement().cleHachage = (chaine) => `hash de ${chaine}`; | ||
|
||
return axios.get(`http://localhost:${port}/auth/cles_publiques`) | ||
.then((reponse) => { | ||
expect(reponse.status).toEqual(200); | ||
expect(reponse.data).toEqual({ | ||
keys: [ | ||
{ | ||
kid: 'hash de 503as-2qay5...', | ||
kty: 'RSA', | ||
use: 'enc', | ||
e: 'AQAB', | ||
n: '503as-2qay5...', | ||
}], | ||
}); | ||
}) | ||
.catch(leveErreur); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters