How do I get POCO SecureSMTPClientSession class to work, using NetSSL_Win module? - smtp

I have built Poco 1.11 and am unable to get secure SMTP connections, or HTTPS connections in general, to work, with the NetSSL_Win module (i.e. using Windows Schannel rather than OpenSSL). There is a sample in the distribution at NetSSL_Win\samples\Mail\src :
SecureSMTPClientSession session(mailhost);
session.login();
session.startTLS(pContext);
if ( !username.empty() )
{
session.login(SMTPClientSession::AUTH_LOGIN, username, password);
}
session.sendMessage(message);
session.close();
When I run it, the second login() call, after the startTLS() call, throws this error:
SSL Exception: Failed to decode data: The specified data could not be decrypted
The server in this case was smtp.gmail.com, on port 587.
I get the same error message for any other HTTPS client code I try to run as well.
Is anyone successfully using Poco 1.11 for HTTPS connections, using Windows Schannel?

Related

An error occurred using the connection to database '' on server ''. .NET Core Web API 7.0

I'm setting up a web API. My program.cs file looks like this:
var serverVersion = new MySqlServerVersion(new Version(8, 0, 29));
builder.Services.AddDbContext<GameDbContext>(
dbContextOptions => dbContextOptions
.UseMySql(builder.Configuration.GetConnectionString("Db"), serverVersion, mySqlOptions =>
mySqlOptions.EnableRetryOnFailure(
maxRetryCount: 10,
maxRetryDelay: TimeSpan.FromSeconds(30),
errorNumbersToAdd: null))
);
And my connection string has the following template:
"ConnectionStrings": {
"Db": "Server=serverIP,port;Database=dbName;User Id=userId;Password=password;"
}
The API ill listen on localhost:7272 when building and running the project in Visual Studio itself. The API will handle the requests sent to this adress.
However, when I build and publish the project and then run the executable from the folder, it listens to localhost:5000, but no requests will be handled because of this error:
An error occurred using the connection to database '' on server ''.
I've already added the 'EnableRetryOnFailure' as suggested by others and changed the template of the connection string multiple times but still to no avail.
What can I do to fix this?
Thanks!
I've already added the 'EnableRetryOnFailure' as suggested by others and changed the template of the connection string multiple times but still to no avail. I also added the Pomelo package.

Connect to AWS IoT MessageBroker with SigV4 presignedURL using Eclipse Paho MQTT client

I am trying to create a Java Mqtt Client using Eclipse Paho which can connect to an AWS IoT MessageBroker using a SigV4 presigned URL generated using AwsIotWebSocketUrlSigner's getSignedUrl method. This connection will be using MQTT over Websockets and has a URL syntax starting with "wss://".
The connection code looks like this.
IMqttAsyncClient client = new MqttAsyncClient(*presignedUrl*,MqttAsyncClient.generateClientId(), new MemoryPersistence());
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
IMqttToken token = client.connect(options);
token.waitForCompletion();
client.setCallback( *callBackObject* );
client.subscribe(topic, AWSIotQos.QOS1.getValue());
I keep getting below Exception. It's failing at the connect() above.
MqttException (0) - java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
at java.lang.Thread.run(Thread.java:749)
Caused by: java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:133)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:74)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:77)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
In Eclipse Paho code Exception happens here while validating the WSS Handshake.
String connectionHeader = (String) headerMap.get(HTTP_HEADER_CONNECTION);
if (connectionHeader == null || connectionHeader.equalsIgnoreCase(HTTP_HEADER_CONNECTION_VALUE)) {
throw new IOException("WebSocket Response header: Incorrect connection header");
}
I am able to connect using a Javascript client and presignedUrl.
Any help/sample code will is much appreciated.
Found this while looking at how AWS Sdk does it as it uses Eclipse Paho underneath. https://github.com/aws/aws-iot-device-sdk-java/blob/647449e654096172ebfcc31d79a8c582f952219d/aws-iot-device-sdk-java/src/main/java/com/amazonaws/services/iot/client/core/AwsIotWebsocketConnection.java#L46
It was adding port no 443 to the clientEndpoint. Apparently the presignedUrl I had was not having it. So I changed the signingUrl to also have port no and it worked.

Apacha HttpClient configuration

I'm currently using RestTemplate backed by Apache http client 4.5.6 in my web server for making http requests. My HttpClient configuration is as follows:
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(httpConfigurationProperties.getConnection().getMaxTotal());
connectionManager.setDefaultMaxPerRoute(httpConfigurationProperties.getConnection()
return HttpClients.custom()
.setDefaultRequestConfig(RequestConfig
.custom()
.setConnectionRequestTimeout((int) httpConfigurationProperties.getTimeout().getConnectionRequestTimeout().toMillis())
.setConnectTimeout((int) httpConfigurationProperties.getTimeout().getConnectTimeout().toMillis())
.setSocketTimeout((int) httpConfigurationProperties.getTimeout().getReadTimeout().toMillis())
.build())
.setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE)
.setConnectionManager(connectionManager)
.build();
When I make a HTTP GET, once in a while i see this:
I/O exception (java.net.SocketException) caught when processing
request to {s}->: Connection reset
I have read in another post that this is caused by server(that I'm sending request to) closing the connection without informing client. And StandardHttpRequestRetryHandler was able to retry it. But HTTP POST methods are not retried because they are not idempotent operations. But is there a configuration that can avoid this connection reset in first place?
And I have tried using evictExpiredConnections and does not help. Will setting connectionManager.setValidateAfterInactivity(20000) help validating connection before using?
Before using apache http client I used SimpleClientHttpRequestFactory in RestTemplate and I never faced connection reset issues. Any help is appreciated

Fail to replicate a local IndexedDB to a remote CouchDB using PouchDB

I'm using PouchDB 7.0.0 in an Ionic project (Ionic 4.0.5).
Within a provider, I define both a local and a remote database:
#Injectable()
export class DatabaseProvider {
constructor() {
this.db = new PouchDB("mydb");
this.remote = new PouchDB("http://<my_server_running_couchdb>/<remote_db_name>")
}
The local database lives in the Chrome browser as an IndexedDB instance. However, the problem also occurs in Firefox so it does not look like the browser is the guy to blame.
The remote database is initially empty and runs on CouchDB 2.1.2. It has already been created on my server with no admin or member set up, so it should be public and allow non-authenticated requests. By the way, CORS are enabled as well.
In the same provider I also define a method that triggers a replication from the local db to the remote node:
replicateLocalDBToRemote() {
console.log("Replicating database...");
this.db.replicate.to(this.remote).then(() => {
console.log("Celebrate");
}).catch(error => {
console.error(error)
})
}
And here is what the call to replicateLocalDBToRemote throws at me
CustomPouchError {__zone_symbol__currentTask: e, result: {…}}
result:
doc_write_failures: 0
docs_read: 0
docs_written: 0
end_time: "2018-11-21T16:23:36.974Z"
errors: []
last_seq: 0
ok: false
start_time: "2018-11-21T16:23:36.874Z"
status: "aborting"
and I am afraid I can't call this a self-explanatory message.
Any guess on what might be the root cause of the issue?
EDIT: After crawling through the PouchDB repo on github, I found this entry which might refer to the same problem.
I fixed the problem by allowing traffic through port 5984 on my remote CouchDB server.
The thing is, sending requests on port 80 (i.e. GET http://<my_server>.com/mydb) does send back some data so I never bothered to try with port 5984 in the first place because I thought the API was also implemented on port 80...
So at least my issue had nothing to do with PouchDB but I wish the error message was a bit more specific.

Salesforce connection with proxy not working

I've a big problem getting the connection to Salesforce test environment (https://test.salesforce.com/services/Soap/u/37.0).
I'm using Wildfly 10.0 as webserver and I've also tried to set the proxy in the standalone configuration.
This is my code:
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(password);
config.setAuthEndpoint(endpoint);
config.setServiceEndpoint(endpoint);
config.setProxy(proxy_host, Integer.parseInt(proxy_port));
config.setProxyUsername(proxy_username);
config.setProxyPassword(proxy_password);
this.connection = Connector.newConnection(config);
In my working environment I've no problem with the connection because we have a proxy without authentication and it connects configuring just proxy_host and proxy_port.
In the customer environment, instead, I have the following exception despite I've configured all the proxy parameters correctly (including username and password):
com.sforce.ws.ConnectionException: Failed to send request to https://test.salesforce.com/services/Soap/u/37.0
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:121)
at com.sforce.soap.partner.PartnerConnection.login(PartnerConnection.java:1426)
at com.sforce.soap.partner.PartnerConnection.<init>(PartnerConnection.java:406)
at com.sforce.soap.partner.Connector.newConnection(Connector.java:27)
.....
Caused by: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 authenticationrequired"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.sforce.ws.transport.JdkHttpTransport.connectRaw(JdkHttpTransport.java:136)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:100)
at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:95)
at com.sforce.ws.transport.JdkHttpTransport.connect(JdkHttpTransport.java:91)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:95)
The proxy configuration is working properly in telnet for istance.
Any idea?
Thanks in advance!!