﻿⍝ Demo Part 1: Using SSH to start an shell our Amazon instance

]load c:\devt\aplssh\APLProcess.dyalog

host←'ec2-35-177-228-55.eu-west-2.compute.amazonaws.com'
amazon←⎕NEW SSH.Session(host 22)    
user←'ec2-user'

public←'C:\Users\mkrom\Documents\SSH\amazon1.pub' 
private←'C:\Users\mkrom\Documents\SSH\amazon1.openssh.ppk'
amazon.Userauth_Publickey user public private ''

SH←{(⎕UCS 13)@(=∘(⎕UCS 10))⎕UCS 2⊃⍺.Exec ⍵}
amazon SH 'uname -a'

⍝ Demo Part 2: Using SSH to start an APL Process on our Amazon instance

exe←'/opt/mdyalog/16.0/64/unicode/mapl' ⍝ NB not runtime
wsid←'/home/ec2-user/TP2/StartPrimeServer.dws'
opts←'MAXWS=1G PORT=8123'
ride_init←'SERVE::4502'

amazon SH 'ps -ef|grep dyalog' ⍝ check no APL already running
x←⎕NEW APLProcess (wsid opts(host user public private exe) ride_init)
amazon SH 'ps -ef|grep dyalog'

⍝ Connect RIDE

gc←Conga.Clt host 8123
gc.SendRecv 'CountPrimes' (0 100)
⍝ Demo Part 3: Using Certificates to secure the connection
⍝   ENCRYPT the tranmissions
⍝   VERIFY the endpoints

)copy conga
]load c:\devt\conga-apl\v3\Client -target=Conga

]load c:\sa2\Solutions\PrimeServerSecure
⍝ Morten: Inserted stop in onReceive?
)ed PrimeServerSecure

srv←Conga.Srv 8123 PrimeServerSecure
srv.Start

host←'localhost' ⍝ Certificates not working under Linux today :-(

tc←(2 ⎕NQ '.' 'GetEnvironment' 'Dyalog'),'/TestCertificates'
geoff←⊃DRC.ReadCertFromFile tc,'/client/geoff-cert.pem'
geoff.KeyOrigin←'DER' (tc,'/client/geoff-key.pem')
john←⊃DRC.ReadCertFromFile tc,'/client/john-cert.pem'
john.KeyOrigin←'DER' (tc,'/client/john-key.pem')

gc←Conga.Clt host 8123
gc.certificate←geoff
gc.Connect
gc.SendRecv 'CountPrimes' (0 100)

jc←Conga.Clt host 8123
jc.certificate←john
jc.Connect
jc.SendRecv 'CountPrimes' (0 100)