package Ġnet . cord a . node api . internal Ċ Ċ import Ġnet . cord a . core . crypto . Composite Key Ċ import Ġnet . cord a . core . crypto . generate KeyPair Ċ import Ġnet . cord a . core . identity . C ord a X 5 0 0 Name Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . internal . create Directories Ċ import Ġnet . cord a . core . internal . div Ċ import Ġnet . cord a . core . utilities . trace Ċ import Ġnet . cord a . node api . internal . config . File Based Certificate Store Supplier Ċ import Ġnet . cord a . node api . internal . config . Ssl Configuration Ċ import Ġnet . cord a . node api . internal . crypto . Certificate Type Ċ import Ġnet . cord a . node api . internal . crypto . X 5 0 9 KeyStore Ċ import Ġnet . cord a . node api . internal . crypto . X 5 0 9 Utilities Ċ import Ġnet . cord a . node api . internal . crypto . X 5 0 9 Utilities . DISTRIB UT ED _ NOT ARY _ COMP OS ITE _ KEY _ ALIAS Ċ import Ġnet . cord a . node api . internal . crypto . X 5 0 9 Utilities . DISTRIB UT ED _ NOT ARY _ KEY _ ALIAS Ċ import Ġnet . cord a . node api . internal . crypto . X 5 0 9 Utilities . NODE _ IDENTITY _ KEY _ ALIAS Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġjava . nio . file . Path Ċ import Ġjava . security . KeyPair Ċ import Ġjava . security . PublicKey Ċ import Ġjava . security . cert . X 5 0 9 Certificate Ċ import Ġjavax . security . auth . x 5 0 0 . X 5 0 0 Principal Ċ Ċ /** Ċ Ġ* ĠContains Ġutility Ġmethods Ġfor Ġgenerating Ġident ities Ġfor Ġa Ġnode . Ċ Ġ* Ċ Ġ* ĠWARNING : ĠThis Ġis Ġnot Ġapplication Ġfor Ġproduction Ġuse . Ċ Ġ*/ Ċ object ĠDev Identity Generator Ġ{ ĊĠĠĠ Ġprivate Ġval Ġlog Ġ= ĠLoggerFactory . getLogger ( java Class ) ĊĊĠĠĠ Ġ/** ĠInstall Ġa Ġnode Ġkey Ġstore Ġfor Ġthe Ġgiven Ġnode Ġdirectory Ġusing Ġthe Ġgiven Ġlegal Ġname . Ġ*/ ĊĠĠĠ Ġfun Ġinstall KeyStore With Node Identity ( node Dir : ĠPath , Ġlegal Name : ĠC ord a X 5 0 0 Name ): ĠParty Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcertificates Directory Ġ= Ġnode Dir Ġ/ Ġ" certificates " ĊĠĠĠĠĠĠĠ Ġval Ġsigning Cert Store Ġ= ĠFile Based Certificate Store Supplier ( certificates Directory Ġ/ Ġ" node keystore . j ks ", ĠDEV _ CA _ KEY _ STORE _ PASS , ĠDEV _ CA _ KEY _ STORE _ PASS ) ĊĠĠĠĠĠĠĠ Ġval Ġp 2 p KeyStore Ġ= ĠFile Based Certificate Store Supplier ( certificates Directory Ġ/ Ġ" ssl keystore . j ks ", ĠDEV _ CA _ KEY _ STORE _ PASS , ĠDEV _ CA _ KEY _ STORE _ PASS ) ĊĠĠĠĠĠĠĠ Ġval Ġp 2 p Trust Store Ġ= ĠFile Based Certificate Store Supplier ( certificates Directory Ġ/ Ġ" trust store . j ks ", ĠDEV _ CA _ TR UST _ STORE _ PASS , ĠDEV _ CA _ TR UST _ STORE _ PRIVATE _ KEY _ PASS ) ĊĠĠĠĠĠĠĠ Ġval Ġp 2 p Ssl Config Ġ= ĠS sl Configuration . mut ual ( p 2 p KeyStore , Ġp 2 p Trust Store ) ĊĊĠĠĠĠĠĠĠ Ġcertificates Directory . create Directories () ĊĠĠĠĠĠĠĠ Ġval Ġnode KeyStore Ġ= Ġsigning Cert Store . get ( true ). also Ġ{ Ġit . install Dev Node Ca Cert Path ( legal Name ) Ġ} ĊĠĠĠĠĠĠĠ Ġp 2 p Ssl Config . key Store . get ( true ). also Ġ{ Ġit . register Dev P 2 p Certificates ( legal Name ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġidentity Ġ= Ġnode KeyStore . store Legal Identity ( NODE _ IDENTITY _ KEY _ ALIAS ) ĊĠĠĠĠĠĠĠ Ġreturn Ġidentity . party ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĠGenerates Ġa ĠC FT Ġnot ary Ġidentity , Ġwhere Ġthe Ġentire Ġcluster Ġshares Ġa Ġkey Ġpair . Ġ*/ ĊĠĠĠ Ġfun Ġgenerate Distributed Not ary Sing ular Identity ( dirs : ĠList < Path >, Ġnot ary Name : ĠC ord a X 5 0 0 Name ): ĠParty Ġ{ ĊĠĠĠĠĠĠĠ Ġrequire ( dirs . isNotEmpty ()) {" At Ġleast Ġone Ġdirectory Ġto Ġgenerate Ġidentity Ġfor Ġmust Ġbe Ġspecified "} ĊĊĠĠĠĠĠĠĠ Ġlog . trace Ġ{ Ġ" Generating Ġsingular Ġidentity Ġ\"$ not ary Name \" Ġfor Ġnodes : Ġ${ dirs . join ToString () }" Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġkey Pair Ġ= Ġgenerate KeyPair () ĊĠĠĠĠĠĠĠ Ġval Ġnot ary Key Ġ= Ġkey Pair . public ĊĊĠĠĠĠĠĠĠ Ġdirs . forEach Ġ{ Ġnode Dir Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġkey Store Ġ= ĠgetKey Store ( node Dir ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset PrivateKey ( key Store , Ġkey Pair , Ġnot ary Name . x 5 0 0 Principal ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn ĠParty ( not ary Name , Ġnot ary Key ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĠGenerates Ġa ĠB FT Ġnot ary Ġidentity : Ġindividual Ġkey Ġpairs Ġfor Ġeach Ġcluster Ġmember , Ġand Ġa Ġshared Ġcomposite Ġkey . Ġ*/ ĊĠĠĠ Ġfun Ġgenerate Distributed Not ary Composite Identity ( dirs : ĠList < Path >, Ġnot ary Name : ĠC ord a X 5 0 0 Name , Ġthreshold : ĠInt Ġ= Ġ 1 ): ĠParty Ġ{ ĊĠĠĠĠĠĠĠ Ġrequire ( dirs . isNotEmpty ()) {" At Ġleast Ġone Ġdirectory Ġto Ġgenerate Ġidentity Ġfor Ġmust Ġbe Ġspecified "} ĊĊĠĠĠĠĠĠĠ Ġlog . trace Ġ{ Ġ" Generating Ġcomposite Ġidentity Ġ\"$ not ary Name \" Ġfor Ġnodes : Ġ${ dirs . join ToString () }" Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġkey Pairs Ġ= Ġ( 1 .. dirs . size ). map Ġ{ Ġgenerate KeyPair () Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġnot ary Key Ġ= ĠComposite Key . Builder (). add Keys ( key Pairs . map Ġ{ Ġit . public Ġ}). build ( threshold ) ĊĊĠĠĠĠĠĠĠ Ġkey Pairs . zip ( dirs ) Ġ{ Ġkey Pair , Ġnode Dir Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġkey Store Ġ= ĠgetKey Store ( node Dir ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset PrivateKey ( key Store , Ġkey Pair , Ġnot ary Name . x 5 0 0 Principal ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Composite Key ( key Store , Ġnot ary Key , Ġnot ary Name . x 5 0 0 Principal ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn ĠParty ( not ary Name , Ġnot ary Key ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠgetKey Store ( node Dir : ĠPath ): ĠX 5 0 9 KeyStore Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdist Serv KeyStore File Ġ= Ġnode Dir Ġ/ Ġ" certificates / distributed Service . j ks " ĊĠĠĠĠĠĠĠ Ġreturn ĠX 5 0 9 KeyStore . from File ( dist Serv KeyStore File , ĠDEV _ CA _ KEY _ STORE _ PASS , Ġcreate New Ġ= Ġtrue ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġset PrivateKey ( key Store : ĠX 5 0 9 KeyStore , Ġkey Pair : ĠKey Pair , Ġnot ary Principal : ĠX 5 0 0 Principal ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġservice Key Cert Ġ= Ġcreate Certificate ( key Pair . public , Ġnot ary Principal ) ĊĠĠĠĠĠĠĠ Ġkey Store . set PrivateKey ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDI STRIB UT ED _ NOT ARY _ KEY _ ALIAS , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġkey Pair . private , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( service Key Cert , ĠDEV _ INTER MEDI ATE _ CA . certificate , ĠDEV _ ROOT _ CA . certificate ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDEV _ CA _ KEY _ STORE _ PASS Ġ// ĠUnfortunately Ġwe Ġhave Ġto Ġuse Ġthe Ġsame Ġpassword Ġfor Ġprivate Ġkey Ġdue Ġto ĠArt emis Ġlimitation , Ġfor Ġmore Ġdetails Ġplease Ġsee : ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġorg . apache . activ emq . art emis . core . rem oting . impl . ssl . SSL Support . load Key ManagerFactory ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġwhere Ġit Ġis Ġcalling Ġ` Key ManagerFactory . init ()` Ġwith Ġstore Ġpassword ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ/* DEV _ CA _ PRIVATE _ KEY _ PASS */) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġset Composite Key ( key Store : ĠX 5 0 9 KeyStore , Ġcomposite Key : ĠPublicKey , Ġnot ary Principal : ĠX 5 0 0 Principal ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcomposite Key Cert Ġ= Ġcreate Certificate ( composite Key , Ġnot ary Principal ) ĊĠĠĠĠĠĠĠ Ġkey Store . set Certificate ( DISTRIB UT ED _ NOT ARY _ COMP OS ITE _ KEY _ ALIAS , Ġcomposite Key Cert ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Certificate ( publicKey : ĠPublicKey , Ġprincipal : ĠX 5 0 0 Principal ): ĠX 5 0 9 Certificate Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠX 5 0 9 Utilities . create Certificate ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCertificate Type . SERVICE _ IDENTITY , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDEV _ INTER MEDI ATE _ CA . certificate , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠDEV _ INTER MEDI ATE _ CA . key Pair , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprincipal , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠpublicKey ) ĊĠĠĠ Ġ} Ċ } Ċ