Permalink
Browse files

TLS support using Windows' SSPI SChannel

  • Loading branch information...
stijnsanders committed Dec 30, 2017
1 parent d61bd80 commit d2c99a11d9d2641a983c336f39ccd8224532a1d5
Showing with 562 additions and 19 deletions.
  1. +28 −11 mongoWire.pas
  2. +534 −8 simpleSock.pas
View
@@ -6,7 +6,7 @@
Made available under terms described in file "LICENSE"
https://github.com/stijnsanders/TMongoWire
v1.1.0
v1.2.0
}
unit mongoWire;
@@ -41,6 +41,8 @@ TMongoWire=class(TObject)
procedure Open(const ServerName: string = 'localhost';
Port: integer = 27017);
procedure OpenSecure(const ServerName: string = 'localhost';
Port: integer = 27017);
procedure Close;
function Get(
@@ -171,7 +173,7 @@ constructor TMongoWire.Create(const NameSpace: WideString);
begin
inherited Create;
FNameSpace:=NameSpace;
FSocket:=TTcpSocket.Create;
FSocket:=nil;
FData:=TMemoryStream.Create;
FData.Size:=MongoWireStartDataSize;//start keeping some data
FWriteLock:=TCriticalSection.Create;
@@ -182,7 +184,7 @@ constructor TMongoWire.Create(const NameSpace: WideString);
destructor TMongoWire.Destroy;
begin
FSocket.Free;
if FSocket<>nil then FSocket.Free;
FData.Free;
FWriteLock.Free;
FReadLock.Free;
@@ -191,22 +193,37 @@ destructor TMongoWire.Destroy;
end;
procedure TMongoWire.Open(const ServerName: string; Port: integer);
var
i,l:integer;
begin
FSocket.Disconnect;
if FSocket<>nil then
begin
FSocket.Disconnect;
FSocket.Free;
end;
FSocket:=TTcpSocket.Create;
FSocket.Connect(ServerName,Port);
if not FSocket.Connected then
raise EMongoConnectFailed.Create(
'MongoWire: failed to connect to "'+ServerName+':'+IntToStr(Port)+'"');
end;
procedure TMongoWire.OpenSecure(const ServerName: string; Port: integer);
begin
if FSocket<>nil then
begin
FSocket.Disconnect;
FSocket.Free;
end;
FSocket:=TTcpSecureSocket.Create;
FSocket.Connect(ServerName,Port);
if not FSocket.Connected then
raise EMongoConnectFailed.Create(
'MongoWire: failed to connect to "'+ServerName+':'+IntToStr(Port)+'"');
i:=1;
l:=4;
setsockopt(FSocket.Handle,IPPROTO_TCP,TCP_NODELAY,@i,l);
end;
procedure TMongoWire.Close;
begin
FSocket.Disconnect;
if FSocket<>nil then
FSocket.Disconnect;
end;
procedure TMongoWire.DataCString(const x:WideString);
@@ -227,7 +244,7 @@ procedure TMongoWire.OpenMsg(OpCode,Flags:integer;const Collection:WideString);
p:PMongoWireMsgHeader;
begin
//assert caller did FQueueLock !!!
if not FSocket.Connected then
if (FSocket=nil) or not(FSocket.Connected) then
raise EMongoNotConnected.Create('MongoWire: not connected');
//message header
p:=FData.Memory;
Oops, something went wrong.

0 comments on commit d2c99a1

Please sign in to comment.