package Ġnet . cord a . node . internal Ċ Ċ import Ġnet . cord a . core . utilities . logger For Ċ import Ġnet . cord a . node . services . config . Node Configuration Ċ import Ġnet . cord a . node . services . config . configure With Dev SS LC ertificate Ċ import Ġnet . cord a . node api . internal . config . Certificate Store Ċ import Ġnet . cord a . node api . internal . crypto . X 5 0 9 Utilities Ċ import Ġnet . cord a . node api . internal . crypt oser vice . Crypto Service Ċ import Ġnet . cord a . node api . internal . crypt oser vice . bouncycastle . B CC rypto Service Ċ import Ġjava . io . IOException Ċ import Ġjava . security . KeyStore Exception Ċ import Ġjava . security . cert . X 5 0 9 Certificate Ċ Ċ private Ġdata Ġclass ĠAll Certificate Stores ( val Ġtrust Store : ĠCertificate Store , Ġval Ġssl KeyStore : ĠCertificate Store , Ġval Ġident ities KeyStore : ĠCertificate Store ) ĊĊ Ċ internal Ġfun ĠNode Configuration . init Key Stores ( crypto Service : ĠCrypto Service ): ĠX 5 0 9 Certificate Ġ{ ĊĠĠĠ Ġif Ġ( dev Mode ) Ġ{ ĊĠĠĠĠĠĠĠ Ġconfigure With Dev SS LC ertificate ( crypto Service ) ĊĠĠĠĠĠĠĠ Ġ// Ġconfigure With Dev SS LC ertificate Ġis Ġa Ġdev Mode Ġprocess Ġthat Ġwrites Ġdirectly Ġto Ġkeystore Ġfiles , Ġso ĊĠĠĠĠĠĠĠ Ġ// Ġwe Ġshould Ġre - synchron ise ĠB CC rypto Service Ġwith Ġthe Ġupdated Ġkeystore Ġfile . ĊĠĠĠĠĠĠĠ Ġif Ġ( crypto Service Ġis ĠB CC rypto Service ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcrypto Service . res ync Ke yst ore () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġvalidate Key Stores () Ċ } Ċ Ċ private Ġfun ĠNode Configuration . validate Key Stores (): ĠX 5 0 9 Certificate Ġ{ ĊĠĠĠ Ġ// ĠStep Ġ 1 . ĠCheck Ġtrust Store , Ġssl KeyStore Ġand Ġident ities KeyStore Ġexist . ĊĠĠĠ Ġval Ġcert Stores Ġ= Ġtry Ġ{ ĊĠĠĠĠĠĠĠ Ġrequire NotNull ( get Certificate Stores ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" One Ġor Ġmore Ġkey Stores Ġ( identity Ġor ĠTLS ) Ġor Ġtrust Store Ġnot Ġfound . Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Please Ġeither Ġcopy Ġyour Ġexisting Ġkeys Ġand Ġcertificates Ġfrom Ġanother Ġnode , Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" or Ġif Ġyou Ġdon 't Ġhave Ġone Ġyet , Ġfill Ġout Ġthe Ġconfig Ġfile Ġand Ġrun Ġc ord a . jar Ġinitial - registration ." ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠKey Store Exception ) Ġ{ ĊĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException (" At Ġleast Ġone Ġof Ġthe Ġkey stores Ġor Ġtrust store Ġpasswords Ġdoes Ġnot Ġmatch Ġconfiguration .") ĊĠĠĠ Ġ} ĊĠĠĠ Ġ// ĠStep Ġ 2 . ĠCheck Ġthat Ġtrust Store Ġcontains Ġthe Ġcorrect Ġkey - alias Ġentry . ĊĠĠĠ Ġrequire ( X 5 0 9 Utilities . C ORD A _ ROOT _ CA Ġin Ġcert Stores . trust Store ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ" Alias Ġfor Ġtrust Root Ġkey Ġnot Ġfound . ĠPlease Ġensure Ġyou Ġhave Ġan Ġupdated Ġtrust Store Ġfile ." ĊĠĠĠ Ġ} ĊĠĠĠ Ġ// ĠStep Ġ 3 . ĠCheck Ġthat Ġtls Ġkey Store Ġcontains Ġthe Ġcorrect Ġkey - alias Ġentry . ĊĠĠĠ Ġrequire ( X 5 0 9 Utilities . C ORD A _ CLIENT _ TLS Ġin Ġcert Stores . ssl KeyStore ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ" Alias Ġfor ĠTLS Ġkey Ġnot Ġfound . ĠPlease Ġensure Ġyou Ġhave Ġan Ġupdated ĠTLS Ġkey Store Ġfile ." ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠStep Ġ 4 . ĠCheck Ġthat Ġidentity Ġkey Stores Ġcontain Ġthe Ġcorrect Ġkey - alias Ġentry Ġfor ĠNode ĠCA . ĊĠĠĠ Ġrequire ( X 5 0 9 Utilities . C ORD A _ CLIENT _ CA Ġin Ġcert Stores . ident ities KeyStore ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ" Alias Ġfor ĠNode ĠCA Ġkey Ġnot Ġfound . ĠPlease Ġensure Ġyou Ġhave Ġan Ġupdated Ġidentity Ġkey Store Ġfile ." ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠStep Ġ 5 . ĠCheck Ġall Ġcert Ġpaths Ġchain Ġto Ġthe Ġtrusted Ġroot . ĊĠĠĠ Ġval Ġtrust Root Ġ= Ġcert Stores . trust Store [ X 5 0 9 Utilities . C ORD A _ ROOT _ CA ] ĊĠĠĠ Ġval Ġssl Cert Chain Root Ġ= Ġcert Stores . ssl KeyStore . query Ġ{ Ġget Certificate Chain ( X 5 0 9 Utilities . C ORD A _ CLIENT _ TLS ) Ġ}. last () ĊĠĠĠ Ġval Ġnode Ca Cert Chain Root Ġ= Ġcert Stores . ident ities KeyStore . query Ġ{ Ġget Certificate Chain ( X 5 0 9 Utilities . C ORD A _ CLIENT _ CA ) Ġ}. last () ĊĊĠĠĠ Ġrequire ( ssl Cert Chain Root Ġ== Ġtrust Root ) Ġ{ Ġ" TLS Ġcertificate Ġmust Ġchain Ġto Ġthe Ġtrusted Ġroot ." Ġ} ĊĠĠĠ Ġrequire ( node Ca Cert Chain Root Ġ== Ġtrust Root ) Ġ{ Ġ" Client ĠCA Ġcertificate Ġmust Ġchain Ġto Ġthe Ġtrusted Ġroot ." Ġ} ĊĊĠĠĠ Ġreturn Ġtrust Root Ċ } Ċ Ċ private Ġfun ĠNode Configuration . get Certificate Stores (): ĠAll Certificate Stores ? Ġ{ ĊĠĠĠ Ġreturn Ġtry Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġfollowing Ġwill Ġthrow ĠIOException Ġif Ġkey Ġfile Ġnot Ġfound Ġor ĠKey Store Exception Ġif Ġkeystore Ġpassword Ġis Ġincorrect . ĊĠĠĠĠĠĠĠ Ġval Ġssl KeyStore Ġ= Ġp 2 p Ssl Options . key Store . get () ĊĠĠĠĠĠĠĠ Ġval Ġsigning Certificate Store Ġ= Ġsigning Certificate Store . get () ĊĠĠĠĠĠĠĠ Ġval Ġtrust Store Ġ= Ġp 2 p Ssl Options . trust Store . get () ĊĠĠĠĠĠĠĠ ĠAll Certificate Stores ( trust Store , Ġssl KeyStore , Ġsigning Certificate Store ) ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠIOException ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger For < Node Configuration >(). error (" IO Ġexception Ġwhile Ġtrying Ġto Ġvalidate Ġkey stores Ġand Ġtrust store ", Ġe ) ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠ Ġ} Ċ } Ċ