public void writeSECSHPublicKey(Stream outs, String comment) { byte[] pubblob = getPublicKeyBlob(); byte[] pub = StringAux.toBase64(pubblob, 0, pubblob.Length); try { Write(outs, StringAux.getBytes("---- BEGIN SSH2 PUBLIC KEY ----")); Write(outs, cr); Write(outs, StringAux.getBytes("Comment: \"" + comment + "\"")); Write(outs, cr); int index = 0; while (index < pub.Length) { int len = 70; if ((pub.Length - index) < len) { len = pub.Length - index; } outs.Write(pub, index, len); Write(outs, cr); index += len; } Write(outs, StringAux.getBytes("---- END SSH2 PUBLIC KEY ----")); Write(outs, cr); } catch (Exception e) { Console.WriteLine(e); } }
public void writePublicKey(Stream outs, String comment) { byte[] pubblob = getPublicKeyBlob(); byte[] pub = StringAux.toBase64(pubblob, 0, pubblob.Length); try { Write(outs, getKeyTypeName()); Write(outs, space); outs.Write(pub, 0, pub.Length); Write(outs, space); Write(outs, StringAux.getBytes(comment)); Write(outs, cr); } catch (Exception e) { Console.WriteLine(e); } }
public void writePrivateKey(Stream outs) { byte[] plain = getPrivateKey(); byte[][] _iv = new byte[1][]; byte[] encoded = encrypt(plain, _iv); byte[] iv = _iv[0]; byte[] prv = StringAux.toBase64(encoded, 0, encoded.Length); try { Write(outs, getBegin()); Write(outs, cr); if (passphrase != null) { Write(outs, header[0]); Write(outs, cr); Write(outs, header[1]); for (int j = 0; j < iv.Length; j++) { outs.WriteByte(b2a((byte)((iv[j] >> 4) & 0x0f))); outs.WriteByte(b2a((byte)(iv[j] & 0x0f))); } Write(outs, cr); Write(outs, cr); } int i = 0; while (i < prv.Length) { if (i + 64 < prv.Length) { outs.Write(prv, i, 64); Write(outs, cr); i += 64; continue; } outs.Write(prv, i, prv.Length - i); Write(outs, cr); break; } Write(outs, getEnd()); Write(outs, cr); //outs.close(); } catch (Exception e) { Console.WriteLine(e); } }
public void connect(ISocketFactory socket_factory, String host, int port, int timeout) { try { if (socket_factory == null) { socket = TcpSocketCreator.CreateSocket(proxy_host, proxy_port, timeout); ins = socket.getInputStream(); outs = socket.getOutputStream(); } else { socket = socket_factory.createSocket(proxy_host, proxy_port); ins = socket_factory.getInputStream(socket); outs = socket_factory.getOutputStream(socket); } if (timeout > 0) { socket.setSoTimeout(timeout); } socket.setTcpNoDelay(true); StreamAux.write(outs, StringAux.getBytesUTF8("CONNECT " + host + ":" + port + " HTTP/1.0\r\n")); if (user != null && passwd != null) { byte[] _code = StringAux.getBytesUTF8((user + ":" + passwd)); _code = StringAux.toBase64(_code, 0, _code.Length); StreamAux.write(outs, StringAux.getBytesUTF8("Proxy-Authorization: Basic ")); StreamAux.write(outs, _code); StreamAux.write(outs, StringAux.getBytesUTF8("\r\n")); } StreamAux.write(outs, StringAux.getBytesUTF8("\r\n")); StreamAux.flush(outs); int foo = 0; StringBuilder sb = new StringBuilder(); while (foo >= 0) { foo = ins.ReadByte(); if (foo != 13) { sb.Append((char)foo); continue; } foo = ins.ReadByte(); if (foo != 10) { continue; } break; } if (foo < 0) { throw new System.IO.IOException(); } String response = sb.ToString(); String reason = "Unknow reason"; int code = -1; try { foo = response.IndexOf(' '); int bar = response.IndexOf(' ', foo + 1); code = int.Parse(response.Substring(foo + 1, bar - (foo + 1))); reason = response.Substring(bar + 1); } catch //(JException e) { } if (code != 200) { throw new System.IO.IOException("proxy error: " + reason); } /* * while(foo>=0){ * foo=in.read(); if(foo!=13) continue; * foo=in.read(); if(foo!=10) continue; * foo=in.read(); if(foo!=13) continue; * foo=in.read(); if(foo!=10) continue; * break; * } */ int count = 0; while (true) { count = 0; while (foo >= 0) { foo = ins.ReadByte(); if (foo != 13) { count++; continue; } foo = ins.ReadByte(); if (foo != 10) { continue; } break; } if (foo < 0) { throw new System.IO.IOException(); } if (count == 0) { break; } } } catch (RuntimeException e) { try { if (socket != null) { socket.close(); } } catch //(JException eee) { } String message = "ProxyHTTP: " + e.ToString(); throw e; } }