@@ -33,13 +33,11 @@ interface CipherData {
3333export class PasswdService extends AbstractService {
3434 public static readonly RANDOM_BYTES_K = 16 ;
3535 public static readonly RANDOM_BYTES_IV = 12 ;
36- public static readonly RANDOM_BYTES_CODE = 5 ;
3736
3837 public static readonly TOKEN_ALGORITHM = 'aes-256-gcm' ;
3938
4039 public static readonly TOKEN_EXPIRATION = 604800 ;
41- public static readonly CODE_EXPIRATION = 900 ;
42- public static readonly CODE_PADDING = '000000000000000000000000000'
40+ public static readonly CODE_EXPIRATION = 1900 ;
4341 public constructor (
4442 protected readonly backends : BackendsService ,
4543 protected readonly identities : IdentitiesService ,
@@ -131,9 +129,7 @@ export class PasswdService extends AbstractService {
131129 throw new BadRequestException ( {
132130 message : 'Erreur serveur lors de l envoi du mail' ,
133131 error : "Bad Request" ,
134- statusCode : 400 ,
135- job,
136- _debug,
132+ statusCode : 400
137133 } ) ;
138134 } )
139135
@@ -226,19 +222,20 @@ export class PasswdService extends AbstractService {
226222 token = decodeURIComponent ( token )
227223 const result = await this . redis . get ( token ) ;
228224 const cypherData : TokenData = JSON . parse ( result ) ;
229-
225+ this . logger . log ( 'decrypt ' + cypherData )
230226 if ( cypherData ?. iv === undefined || cypherData ?. k === undefined || cypherData ?. tag === undefined ) {
231227 throw new NotFoundException ( 'Invalid token' ) ;
232228 }
233- const padd = this . getPaddingForCode ( ) ;
229+ const padd = await this . getPaddingForCode ( ) ;
234230 const k = padd + code . toString ( 16 )
231+ this . logger . log ( 'k=' + k )
235232 const decipher = crypto . createDecipheriv ( PasswdService . TOKEN_ALGORITHM , k , cypherData . iv ) ;
236233 decipher . setAuthTag ( Buffer . from ( cypherData . tag , 'base64' ) ) ;
237234 const plaintext = decipher . update ( token , 'base64' , 'ascii' ) ;
238235 return JSON . parse ( plaintext ) ;
239236 } catch ( error ) {
240- this . logger . verbose ( "Error while decrypting token. " + error + ` (token=${ token } )` ) ;
241- throw new BadRequestException ( 'Invalid token' ) ;
237+ this . logger . error ( "Error while decrypting token. " + error + ` (token=${ token } )` ) ;
238+ throw new BadRequestException ( 'Invalid token xx ' ) ;
242239 }
243240 }
244241 public async decryptToken ( token : string ) : Promise < CipherData > {
@@ -262,13 +259,15 @@ export class PasswdService extends AbstractService {
262259 }
263260 }
264261 public async resetByCode ( data :ResetByCodeDto ) :Promise < [ Jobs , any ] > {
262+ this . logger . log ( 'resetByCode : ' + data . token + ' ' + data . code )
265263 const tokenData = await this . decryptTokenWithCode ( data . token , data . code )
264+ this . logger . log ( 'dataToken :' + tokenData )
266265 try {
267266 const identity = await this . identities . findOne ( { 'inetOrgPerson.uid' : tokenData . uid } ) as Identities ;
268267 const [ _ , response ] = await this . backends . executeJob (
269268 ActionType . IDENTITY_PASSWORD_RESET ,
270269 identity . _id ,
271- { uid : tokenData . uid , newPassword : data . newPassword , ...pick ( identity , [ 'inetOrgPerson' ] ) } ,
270+ { uid : tokenData . uid , newPassword : data . newpassword , ...pick ( identity , [ 'inetOrgPerson' ] ) } ,
272271 {
273272 async : false ,
274273 timeoutDiscard : true ,
@@ -278,6 +277,7 @@ export class PasswdService extends AbstractService {
278277 ) ;
279278
280279 if ( response ?. status === 0 ) {
280+ this . logger . log ( 'delete key' )
281281 await this . redis . del ( data . token ) ;
282282 return [ _ , response ] ;
283283 }
0 commit comments