Commit 3f4d0426 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Also test existing Android keyshare registration

parent cce18c8d
......@@ -81,6 +81,19 @@ func verifyManagerIsUnmarshaled(t *testing.T) {
)
}
func verifyCredentials(t *testing.T) {
for credtype, credsmap := range Manager.credentials {
for index, cred := range credsmap {
require.True(t,
cred.Credential.Signature.Verify(cred.PublicKey(), cred.Attributes),
"Credential %s-%d was invalid", credtype.String(), index,
)
require.Equal(t, cred.Attributes[0], Manager.secretkey,
"Secret key of credential %s-%d unequal to main secret key")
}
}
}
func verifyPaillierKey(t *testing.T, PrivateKey *paillierPrivateKey) {
require.NotNil(t, PrivateKey)
require.NotNil(t, PrivateKey.L)
......@@ -144,6 +157,7 @@ func TestAndroidParse(t *testing.T) {
parseAndroidStorage(t)
verifyManagerIsUnmarshaled(t)
verifyCredentials(t)
verifyKeyshareIsUnmarshaled(t)
teardown(t)
......@@ -158,6 +172,7 @@ func TestUnmarshaling(t *testing.T) {
require.NoError(t, err)
verifyManagerIsUnmarshaled(t)
verifyCredentials(t)
verifyKeyshareIsUnmarshaled(t)
teardown(t)
......@@ -259,7 +274,7 @@ func TestCandidates(t *testing.T) {
disjunction = &AttributeDisjunction{
Attributes: []AttributeTypeIdentifier{attrtype},
Values: map[AttributeTypeIdentifier]string{attrtype: "s1234567"},
Values: map[AttributeTypeIdentifier]string{attrtype: "456"},
}
attrs = Manager.Candidates(disjunction)
require.NotNil(t, attrs)
......
......@@ -118,7 +118,10 @@ func newKeyshareServer(privatekey *paillierPrivateKey, url, email string) (ks *k
func (ks *keyshareServer) HashedPin(pin string) string {
hash := sha256.Sum256(append(ks.Nonce, []byte(pin)...))
return base64.RawStdEncoding.EncodeToString(hash[:])
// We must be compatible with the old Android app here,
// which uses Base64.encodeToString(hash, Base64.DEFAULT),
// which appends a newline.
return base64.StdEncoding.EncodeToString(hash[:]) + "\n"
}
// startKeyshareSession starts and completes the entire keyshare protocol with all involved keyshare servers
......
......@@ -186,21 +186,22 @@ func sessionHelper(t *testing.T, jwtcontents interface{}, url string, init bool)
}
func registerKeyshareServer(t *testing.T) {
bytes := make([]byte, 8, 8)
rand.Read(bytes)
email := fmt.Sprintf("%s@example.com", hex.EncodeToString(bytes))
require.NoError(t, Manager.KeyshareEnroll(NewSchemeManagerIdentifier("test"), email, "12345"))
}
// Register a new account at the keyshare server and do an issuance, disclosure,
// and issuance session, also using irma-demo credentials deserialized from Android storage
func TestKeyshareRegistrationAndSessions(t *testing.T) {
parseStorage(t)
parseAndroidStorage(t)
Manager.credentials[NewCredentialTypeIdentifier("test.test.mijnirma")] = map[int]*credential{}
test := NewSchemeManagerIdentifier("test")
err := Manager.KeyshareRemove(test)
require.NoError(t, err)
bytes := make([]byte, 8, 8)
rand.Read(bytes)
email := fmt.Sprintf("%s@example.com", hex.EncodeToString(bytes))
err = Manager.KeyshareEnroll(test, email, "12345")
require.NoError(t, err)
}
func TestKeyshareSession(t *testing.T) {
registerKeyshareServer(t)
id := NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
......@@ -239,3 +240,47 @@ func TestKeyshareSession(t *testing.T) {
teardown(t)
}
// Use the existing keyshare registration and credentials deserialized from Android storage
// in a keyshare session of each session type.
// Use keyshareuser.sql to register the user at the keyshare server.
func TestKeyshareSessions(t *testing.T) {
parseStorage(t)
parseAndroidStorage(t)
id := NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
expiry := Timestamp(NewMetadataAttribute().Expiry())
credid := NewCredentialTypeIdentifier("test.test.mijnirma")
jwt := getIssuanceJwt("testip", id)
jwt.(*IdentityProviderJwt).Request.Request.Credentials = append(
jwt.(*IdentityProviderJwt).Request.Request.Credentials,
&CredentialRequest{
Validity: &expiry,
Credential: &credid,
Attributes: map[string]string{"email": "example@example.com"},
},
)
sessionHelper(t, jwt, "issue", false)
jwt = getDisclosureJwt("testsp", id)
jwt.(*ServiceProviderJwt).Request.Request.Content = append(
jwt.(*ServiceProviderJwt).Request.Request.Content, //[]*AttributeDisjunction{},
&AttributeDisjunction{
Label: "foo",
Attributes: []AttributeTypeIdentifier{NewAttributeTypeIdentifier("test.test.mijnirma.email")},
},
)
sessionHelper(t, jwt, "verification", false)
jwt = getSigningJwt("testsigclient", id)
jwt.(*SignatureRequestorJwt).Request.Request.Content = append(
jwt.(*SignatureRequestorJwt).Request.Request.Content, //[]*AttributeDisjunction{},
&AttributeDisjunction{
Label: "foo",
Attributes: []AttributeTypeIdentifier{NewAttributeTypeIdentifier("test.test.mijnirma.email")},
},
)
sessionHelper(t, jwt, "signature", false)
teardown(t)
}
INSERT INTO `users` VALUES (485,'testusername',NULL,NULL,NULL,'puZGbaLDmFywGhFDi4vW2G87ZhXpaUsvymZwNJfB/SU=\n',0,'0','241c78b309f8d774f32e0128c9270dc1776d9e1c6e7b763e66961a13f7b2e4df','{\"bits\":2048,\"n\":24428225740399330580333113110902680990277589581067969934949653123683469098494764641155243082249801664112361823434766013151369368511090516353844744830204646148333478565793378429678588341062977096119512869222655526015820538374966936659436617846962895714302754039294374733280764050022433419774087855847938858000332409285415750647466867279610626860664320265681649418469417127726923376741037448704723897078434301858791634189635797437813209386891133527791081093395862543868043852447762291145615589316942332322356214230772589251174590398678888311562947723531989408178115197127709706626583351333795141029721896901485453680319,\"nSquared\":596738212823908422722684447852557873707091115290261109970619471214678688342663922610410225887969624669528632850269713940927164243946500395632609808709015431150143363018916552402305647705542105198182591241256704640058830256989985731530407093712739321579360275605383025599284152574935758439945013820180868488849586876077265724009673310418503195732728223826931331883694710955296016136427784335719332993384794598188249575083799908524468396099680094784562607747368568764227244378367311828084637807486262977349835646107424857193160577841257746953292275449202680334406981680553910026247464478737898189519886148000530227289008009559577110542216066310896228763339224181840338326046626159368526555117143093509692471618025882574619710623665103358362539924521797298689972262499613191997151181825621274686799114758647167482972918231380049134953711377395205821468850062066750831955543485615342319331993871223164126914743303237376899916098170292785384814958681609873987207017471155787970444329874030299436374891262395778674915034144917802416680050500567825951443996313677157331224391722261090993848466707100532265478585766510876455411260719566093960241080627471763474427127437884993041475493613536790376888114934702629672232540326858573261847941761,\"g\":17948470935821729188106091421709655906001732927602280604374877188502926412173732300250736064220436586121644432565867771993761974358949417374879427109114746839901074083831506941188486018803901725486624170545520797943374384178772090444259028702531962880614697282738685021298955994020851975625300141657255060207178035443078641230729905182801310741253760431199512540950387260880637093634480127770357299622052007681045829349269144636555636560022574641155735732745698662647396619247466755278755885560424714760594726764152680178405250922344992316157163182728147747687910564755889459196648180088397022867342119114131262716803}',1,1,0);
\ No newline at end of file
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="currentSessionUrl">{&quot;v&quot;:&quot;2.0&quot;,&quot;vmax&quot;:&quot;2.2&quot;,&quot;u&quot;:&quot;https://privacybydesign.foundation/tomcat/irma_api_server/api/v2/verification/41KX9xWbndQ75XKkn7KWzQe147GoVqgWCVNRjzzkjt2&quot;}</string>
<string name="credentials">{&quot;irma-demo.RU.studentCard&quot;:[{&quot;attributes&quot;:[14311475998953663091065531505246622314743971596222483573582468863831572515763,49043481832371145193140299771658227036446546573739245068,7176348269900990032589055671819815078163577,227710153798026723211059,8300470783721158199,23490470611349108],&quot;signature&quot;:{&quot;A&quot;:51518847797691315727759176802160924436068453812184227246424196546685279013991773736726971138868801946852108718480601819064965386249179533588157069657036939589092421901526806133965140590833131672940709393013243049877736332421020136297605111114121326836065541455506410189976106855792201899165714292644914660210,&quot;e&quot;:259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742930097689232357305283326696435376787951,&quot;v&quot;:38310894672661389818391406324146546161842421274100382134520121199587829637997105856296155591966279915551494648835200040803719876576293413333552935659268579872375460111762931849215961596989032031922044019510380740288454356537834965385050179064636589448201808579140577510338610578765689038649977016690987163056169920632164015353558294297265082648883869731173807173470248058333164759891293549764690925423121339133364530961786457287448868541013089764911054403908770150938708063111861008848653365237335569273912585041}}],&quot;test.test.mijnirma&quot;:[{&quot;public_sks&quot;:[85082025162837201194376665159280932833709502354228382426819253775157607330761605538885353580375270262824918717451102191200845300689661501037194721171086025783504808921909133839891286893734098605996576876074961701903214263017801474730299291177947936831353263293658665257545333300975086052644477159922153700211],&quot;attributes&quot;:[16459692790872044191270191888077408200498233251516520153743596615296136822467,49043497911096929087709751855583038580649425750938808456,6447474],&quot;signature&quot;:{&quot;A&quot;:81938903663175735231102809471715126742263661504178806814107027053419092775383501647567360526313002878919372222469161453175963989485642425148659897546249581008276527236157155114393295966396144041462784398145165053523477816088539594594397193214696516415786505680809951299227861742533992451809935679709699858070,&quot;e&quot;:259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742929994448917446035492429208455891239709,&quot;v&quot;:48956745387547547755788580520650766308330888466036755112855361158740842901483349230915364378175609049787474155793849336004346852796945811448843920046445625148937997946386566322716894319693746371881847355312623694089380606610576034045179484694167943053363626918543702448136931138961238027893421951715865417335028873173100252063514071379131920391685738760184358577919834252703903950553758059838921759305007510427428556493866616689037840541282355139942231935431858600461969395303833033395915723481209566437224100143}}]}</string>
<string name="credentials">{&quot;test.test.mijnirma&quot;:[{&quot;public_sks&quot;:[85082025162837201194376665159280932833709502354228382426819253775157607330761605538885353580375270262824918717451102191200845300689661501037194721171086025783504808921909133839891286893734098605996576876074961701903214263017801474730299291177947936831353263293658665257545333300975086052644477159922153700211],&quot;attributes&quot;:[16459692790872044191270191888077408200498233251516520153743596615296136822467,49043497911096929087709751855583038580649425750938808456,6713199],&quot;signature&quot;:{&quot;A&quot;:45222154268674273710241606712088428574327878157177201139384374721171826461412293659115700357192323970285281190820411677649364221414391111849580700591248745148446158534302920406192967484495995535298878524558192472720010597489395900822557876058305418130894199313225355725563905329921324127951328609858221865688,&quot;e&quot;:259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742930189984109555429399234387572652290181,&quot;v&quot;:37089426574404853314527538425590154464185669611257826737975997075833182365911745361173581237316274982025210017363868383021489436792111663380955676867084118464865738380944058955231525097633962671227066163548711934512602987866484024140781599202158747051737882065397224229528273128088731188352989738315756064211230068049165954427138829408447136906870620401460509477728657639517925540509852663699685295279125577115556094945251824705694439002539764689968101329433910130152847508956031277000706585794137651236318227128}}],&quot;irma-demo.RU.studentCard&quot;:[{&quot;attributes&quot;:[16459692790872044191270191888077408200498233251516520153743596615296136822467,49043497911096929607726931703203423024551950578089278988,23188031866369380,3224115,3421494,5269572],&quot;signature&quot;:{&quot;A&quot;:19361989720240022780364031292670736589482375295351376840389602869290921590081983014245433147598934021651062476173549660545604024910603570251193965749831813974082815089185920569764627738209782651392073734649038157462687171908062832755984081636063543276779686036825699213396941509489370406466435663161305944357,&quot;e&quot;:259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742930225372495635518051503820864567017509,&quot;v&quot;:44504154960997969936163816284867421689230969904501819714082539974281416125028394649804074185982730620713368510527561786489151242878408608924108769812084146129727784097430924126631729595258408129362124864052428072634924023503654055028585711391218571487914853282274713963805294744852479094032534022811676406774207262761522055883100899856663354161806256075693680140216792420850477388497107343316133929461954334492914769220324629269238945857169205525679465959160495511815055891870320672867787549146029373683233228360}}]}</string>
<string name="KeyshareKeypairs">[{&quot;privateKey&quot;:{&quot;lambda&quot;:13105831384828218876560609191189383845468459774975903717604163515386241495802150568081964987040584656142216443261218467199905843616264284055829505412960102329209002173148186420620500504858986845489948534342198615611818161542152957889040110812941118638951231633747249414646837250859544265493362941989058935616412420426887288399954686824856971402713552531155410782666248727292165743388787937137041599325971824628900100322779024857586721474036320187217412019204689610881581773125014731592865210590421717072349044304127053672666150142099179812051526213635630586112552985839971411737662299019137877699120171511254859730164,&quot;preCalculatedDenominator&quot;:14457175043970867415482864202144925492455189514261889829019837221373475922961532698087509388113348555917219818150888564425877887960039812301626028889905753439084324313884963867248924045095099875600061387168880466523954155339779490282034173927659447847503489301273075366512403194118684254876613087496838773003874146757417013864773712276484301281333085093670440601294131086228360118390208800171949963093232479261037074686763095365997465734818160576919422500361850265405516827193794151557746513679590064303202557683348550737040347000242465179752409243222947197749116418194597609990691197111528523135899412968516583651540},&quot;publicKey&quot;:{&quot;bits&quot;:2048,&quot;g&quot;:8862400561053796364289285723617693709207564671698972893812200927472011482035295371791426738073934848329302611254009067210559729810902663585454743512874760511368626382512193855688797707415822966598786461277217956206157765359954321269690961732537704558120157014666258193744608782162606605170876295968514024471141843787498493152932774279687347862057282945272215765332541474211830087002078271212103305702205788341726639534165102630283294218679557529017676396999598448180234664320818005422679066912462307632981889153339448429506228240657156076394029553819588111185770468406271931195208301167982327782614273877364721714452,&quot;n&quot;:26211662769656437753121218382378767690936919549951807435208327030772482991604301136163929974081169312284432886522436934399811687232528568111659010825920204658418004346296372841241001009717973690979897068684397231223636323084305915778080221625882237277902463267494498829293674501719088530986725883978117871233149085456111975665968312781373400475995717615211287938483521093329209078097893122125909937865512298951433144557040805559075433725322232688535699085082726523017873600524842344424677847217387575470418175712809701080214114825687537367951841103742141876774971583300722803037995253856843248026121191810752654274223,&quot;nSquared&quot;:687051265150193397388737817358354735135379425802161838393081206112180852406102336661977328151527128648923978763926029566847881395557111856108083268840036991848093085707643314278670899573615597557018701664652290094225326842794721518120098448299930012617134510178308002775842424437745795941590153105400326680047975875811954487334935179849168841000649942377984466861597973811131227952291501551344177628270089313938769943238235101730045101784480725891585983180996430688827273523156596705718421623185098892388555113844586624798206469811916847146153787351016427620772668531112567616601680420110669419300161427439750870446658944559518310012326431627406431000795002946018420635025636749454943511229471215249620266567874528383434474580509468753325765630060183187621977261956013577372439010654166096800514371315165138841327451799493798885006436386382563574252854758769432824547274991022772773828006940890171431402084684096553511231459009120400723388472707427084637869177106345365952491273341327831008562737754411280436203881971742872052502302361295444174230182249579289657685236067835020312586819531146275049884116649650194408736172295425155849973493156469880872191887812616518885817798547061730519474196414344767522035757131883766150882253729}},{&quot;privateKey&quot;:{&quot;lambda&quot;:6184562678528752436832164133724517995431954528494243017545500208614709651767377714257841240272720630359762916481185037603813113089603005910539770462609596751920347221069059975784159494591218550001024160513862718606573032998680237306637825698955423269983698373452564721617556472176888974747238372962166560567833010090783283721188389989840207700895671602581224918934678281299019936932720319707679785602244082105916618542821207646259753009399823471432247446390285302239068634383996988495890078585007302812815803503820187905484135946066391133081048259187375039757173695608214036865596366509171308574148200704309443764444,&quot;preCalculatedDenominator&quot;:3508628871837896788321309237803440469403117094910460515766494924999724519071930881339056474869035916234214465229551568332862196862718822303382740727624840200833947022860166041718986776724551892102489072337758081929573180080013954625914613005031361367111698086249519496273404229622162026090202929945849942880934660127600271409516420795724912767897223552791438362903310434967491401537026159986167469001871407547237981849744547292474794910841697822927754679818124348830555461024193016084711728120676214139902333529799071190420767988605828092412644423762072877030470209599099389367280815334114438378069068181181058736791},&quot;publicKey&quot;:{&quot;bits&quot;:2048,&quot;g&quot;:17767463921361790475850945292980865995244694782274600798889058583795448595655230498143301060554472153811191834580916447890535273201977466908601236575421197376061431343102813995580354991205876972725742105642561503947039149916280545883075499395400011378310529259383089175649963880461391018852256967958446507954986990641775442845408924114402473837987012378606297814034927688586777297474215574761420358612206306949782968177729624649508752129235873813995151659950110801680628985884778091328842752327266555079541007332946858463967181246818896616753694053118750508390518124287186980282171260678670643565737884142133288589401,&quot;n&quot;:24738250714115009747328656534898071981727818113976972070182000834458838607069510857031364961090882521439051665924740150415252452358412023642159081850438387007681388884276239903136637978364874200004096642055450874426292131994720949226551302795821693079934793493810258886470225888707555898988953491848666242271648010535263876690591371549184488285292852556108098831053527978343953516901065910077176311284006269611726703192096126019674012913721567460759964188566623332994691859022294190618205991695025767206922649752736913034517035271738376896936368149181012410794877117433051973100751732715850680205664609652609815182897,&quot;nSquared&quot;:611981048394411789723953421476186591657368245800249742964177783299044023934931312318209363119887594846270142110975561619889579465125478770329167364521552661288086851944334527163279902570126907655353897552949530794124306755920852822227231995239686092877904605802171681499531667168561357567906188391533682522788232235293791366572590318999881897615294278544337013827080331160473976235198377329447997236604195541220849972135512524975186344029683158152922443280323040459534037669949807801104726623840623446431521636219576592795456066162368515810186259357688010253221756253768239702790645617809312136608532141559952086293992485843555015680373737960019119996233405018158354285517204344155278771773875609002500622993066825638558032745648908015028177280986062730134423851791114197134874632127799901960254934852296501757346247901444214427309573353333305832305947576015980844106755930969830500694326327162385658584413941141105580111707185814694014255678459167853049859388198810341006124599479909199354188941922972516151208685042513959047394859264250891931562156900839282128434254591808713990424035399307841847608314031458201734146013479981075481175837621027322959784838064477702593822887882257219197124070665470650004125120857600979701561312609}},{&quot;privateKey&quot;:{&quot;lambda&quot;:6028452352425011549574554689599013957304376567620389108914889309228356380068768736448966207018145406730900090971639880691225550403987461474965370832235144360059862408691802022992076863036759202505119231885754235889782776029256321349414327482888097914099554837553709457886050735655494927090190765223160674355651062439996244049353775540339080670889141528244222884195409094547781615289755663286309917416217035663165531657176973219486023262309807433629786250843572701879934485104088125299145658970125343979170033308524357589807406620682949863271575020368877325335218820280128557493456704092938888335602385161423779096304,&quot;preCalculatedDenominator&quot;:3111015575808257214670518772849525204347870840158004578696072738298150482248965871739918934218250629792218371362177825593750743110954487007029304470087322461414783573597792822377377423880615389546120263865938012674278853168380322586873515694928469042276233644696817323724605476354007511642267958517478270526145703900692512897264401804623322219889957709078242891956994461492105106273132156096571227213889667952488051138257863582658418999333168957588828154879830515612381503660218818488614774284879432878376926141945314369836270073009299481905490109127401864665903144801039019000377686874436629209724202627596930080910},&quot;publicKey&quot;:{&quot;bits&quot;:2048,&quot;g&quot;:25203586278496337500506037071786988254712368567661125696011348877989440853448499869317337936318942695308886944041024556799277668205445062643855354256855520700517210407765865214248232179503855682691045593895406168112836809590100517023702607999489077052605922778848157674018090064708560658821231622355276053276937628353434808939614883997170419500565941916685408731330720822232008822225148820344504920517262362983268301619949286214234326975080326972806811587474074751841924523127220545356559404043441261683915720957116156670855991432763507861121251204729277534389509491952694073592082976983869193848169368886504777167543,&quot;n&quot;:24113809409700046198298218758396055829217506270481556435659557236913425520275074945795864828072581626923600363886559522764902201615949845899861483328940577440239449634767208091968307452147036810020476927543016943559131104117025285397657309931552391656398219350214837831544202942621979708360763060892642697422915751281710581081623369284366151700951012391659673733039515566976420407336974182888646229967918140018678743366854814391316663891385431677656987687495177684293959235462165870906774333308976445541972903603467802680013422533783174122094147196936065715636382935758285029139504968030589078315813054153083156003909,&quot;nSquared&quot;:581475804247338490488006599248054006626212612976047499356860085147863424328471353817888582048179247652829104006631784465561374923253921265898280459759713808221382918585343558683822468412955134269326608954404008740596489342584451051332963879525566466104631311795594116713746971595658702416152057761216038556229912985015420280677350587257225478435800892298669785494933249479568802951226727955368321803664357645478714252258863288660785400020670185081841142677355955562132095964404351725369088923591102195985188378900133311613738899080830313804105125349940281703868886788457933005100509719731353654310662356640505306354978715848703540364865193532698108383842705254353161156795087969766467669425373796885766152693869110040976302615013464052872815087804986693351139490163877481346915693528053014055280605567258803619880459875779172043771920215323112027680816016961399520435655139291392766279161805529108554823248369627250170542824840801418859756582748372368177568771136838253631221701741119818398556689379982174249981391710099750980453213732658428729858876372531883875959585650375352885213298810434291065509301991961092541282567050346631173852937324752665107296399544140064631759104304928530309602320212301715462344327108289140113623280281}}]</string>
<boolean name="launchedFromBrowser" value="false" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment