Differences From
Artifact [cd7a14ae6e]:
354 354 ::badop :: do co:complain(405, 'invalid operation', 'the operation you have attempted on this post is not meaningful') return end
355 355 ::noauth:: do co:complain(401, 'unauthorized', 'you have not supplied the necessary credentials to perform this operation') return end
356 356 end
357 357
358 358 local terra
359 359 credsec_for_uid(co: &lib.srv.convo, uid: uint64)
360 360 var act = co:ppostv('act')
361 - lib.dbg('showing credentials')
361 + if not act then return true end
362 + lib.dbg('handling credential action')
362 363 if act:cmp( 'invalidate') then
363 364 lib.dbg('setting user\'s cookie validation time to now')
364 365 co.who.source:auth_sigtime_user_alter(uid, lib.osclock.time(nil))
365 366 -- the current session has been invalidated as well, so we need to immediately install a new authentication cookie with the same aid so the user doesn't need to log back in all over again
366 367 co:installkey('?',co.aid)
367 - return
368 - elseif act:cmp( 'newcred') then
368 + return false
369 + elseif act:cmp('revoke') then
370 + var s_cred = co:ppostv('cred')
371 + if s_cred:ref() then
372 + var cred, ok = lib.math.shorthand.parse(s_cred.ptr, s_cred.ct)
373 + if ok then
374 + co.srv:auth_destroy_aid_uid(cred,co.who.id)
375 + end
376 + end
377 + return true
378 + elseif act:cmp('newcred') then
369 379 var cmt = co:ppostv('comment')
370 380 var pw = co:ppostv('newpw')
371 381 var rsapub = co:ppostv('newrsa'):blob()
372 382 var aid: uint64 = 0
373 383 if pw:ref() then
374 384 var cpw = co:ppostv('rptpw')
375 385 if not pw:cmp(cpw) then
376 386 co:complain(400,'enrollment failure','the passwords you supplied do not match')
377 - return
387 + return false
378 388 end
379 389 aid = co.srv:auth_attach_pw(uid, false, pw, cmt)
380 390 elseif rsapub:ref() then
381 391 var sig = co:ppostv('sig')
382 392 var nonce = co:ppostv('nonce')
383 393 var s_noncevld = co:ppostv('noncevld')
384 394 var noncevld, ok = lib.math.shorthand.parse(s_noncevld.ptr, s_noncevld.ct)
385 395 if not ok then
386 396 co:complain(403,'try harder next time','you call that cryptanalysis?')
387 - return
397 + return false
388 398 end
389 399
390 400 var fr = co.srv.pool:frame()
391 401 var hmac = lib.crypt.hmacp(&co.srv.pool, lib.crypt.alg.sha256, co.srv.cfg.secret:blob(), nonce)
392 402 if not lib.math.truncate64(hmac.ptr, hmac.ct) == noncevld then
393 403 co:complain(403,'nice try','what exactly are you trying to accomplish here, buddy')
394 - return
404 + return false
395 405 end
396 406
397 407 var pkres = lib.crypt.loadpub(rsapub.ptr,rsapub.ct+1) -- needs NUL
398 408 if not pkres.ok then
399 409 co:complain(400,'invalid key','the key you have supplied is not a valid PEM or DER file')
400 - return
410 + return false
401 411 end
402 412 var pk = pkres.val
403 413 defer pk:free()
404 414
405 415 var decoded = co.srv.pool:alloc(uint8,sig.ct)
406 416 var decoded_sz: intptr = 0
407 417 if lib.b64.mbedtls_base64_decode(decoded.ptr,sig.ct,&decoded_sz,[&uint8](sig.ptr),sig.ct) ~= 0 then
408 418 co:complain(400,'invalid signature','the signature you supplied is not encoded in valid base64')
409 - return
419 + return false
410 420 end
411 421
412 422 var vfy, secl = lib.crypt.verify(&pk, nonce.ptr, nonce.ct, decoded.ptr, decoded_sz)
413 423 if not vfy then
414 424 co:complain(403,'verification failed','the signature you supplied does not match the required nonce')
415 - return
425 + return false
416 426 end
417 427
418 428 var dbuf: uint8[lib.crypt.const.maxdersz]
419 429 var derkey = lib.crypt.der(true, &pk, &dbuf[0])
420 430 aid = co.srv:auth_attach_rsa(co.who.id, false, derkey, cmt)
421 431 co.srv.pool:reset(fr)
422 432 end
................................................................................
446 456 co.srv:auth_privs_set(aid, privs)
447 457 end
448 458
449 459 lib.dbg('setting netmask restrictions')
450 460 var nm = co:pgetv('netmask')
451 461 end
452 462 co:reroute('?')
453 - return
463 + return false
454 464 end
455 465 co:complain(400,'bad request','the operation you have requested is not meaningful in this context')
466 + return false
456 467 end
457 468
458 469 terra http.configure(co: &lib.srv.convo, path: hpath, meth: method.t)
459 470 var msg = pstring.null()
460 471 -- first things first, do priv checks
461 472 if path.ct >= 2 then
462 473 if not co.who.rights.powers.config() and (
................................................................................
513 524 co.ui_hue = co.srv.cfg.ui_hue
514 525 end
515 526
516 527 msg = 'profile changes saved'
517 528 --user_refresh = true -- not really necessary here, actually
518 529
519 530 elseif path(1):cmp('sec') then
520 - credsec_for_uid(co, co.who.id)
531 + if not credsec_for_uid(co, co.who.id) then return end
521 532 elseif path(1):cmp('avi') then
522 533 var act = co:ppostv('act')
523 534 if act:ref() and act:cmp('clear') then
524 535 co.who.avatarid = 0
525 536 co.who.source:actor_save(co.who)
526 537 msg = 'avatar reset to default'
527 538 else goto badop end
................................................................................
536 547 goto nopriv
537 548 end
538 549 else goto badop end
539 550 defer usr:free()
540 551
541 552 if path.ct == 4 then
542 553 if path(3):cmp(lib.str.lit 'cred') then
543 - credsec_for_uid(co, userid)
554 + if not credsec_for_uid(co, userid) then return end
544 555 end
545 556 elseif path.ct == 3 then
546 557 var purgestr = co:ppostv("purgestr")
547 558 var purgekey = co:ppostv("purgekey")
548 559 if purgestr:ref() and purgekey:ref() and purgestr(0) ~= 0 then
549 560 if purgestr:cmp(purgekey) then -- destroying account! :O
550 561 co.srv:actor_purge_uid(userid)