'How can I make Handshake between client and https server
I'm working on project that requires secure connection between Client (which is Android Device) and Server which is (Nestjs app)
and for generating my certificate I'm using openSSl this is the link I followed
Link : Tuto openSSL
I configured main.ts as shown below :
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
import * as fs from 'fs';
const httpsOptions = {
key: fs.readFileSync('certssl/CA/localhost/localhost.decrypted.key'),
cert: fs.readFileSync('certssl/CA/localhost/localhost.crt'),
};
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
httpsOptions,
});
await app.listen(443);
}
bootstrap();
and this is my gateway.ts file
import { Logger } from '@nestjs/common';
import {
MessageBody,
OnGatewayConnection,
OnGatewayDisconnect,
OnGatewayInit,
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
WsResponse,
} from '@nestjs/websockets';
import { Server, Socket } from 'socket.io';
@WebSocketGateway({
cors: {
origin: '*',
transports: ['polling', 'websocket'],
},
})
export class AppGateway implements OnGatewayInit, OnGatewayDisconnect {
handleDisconnect(client: any) {
this.logger.log(`Disconnected ${client.id}`);
}
@WebSocketServer() server: Server;
private logger: Logger = new Logger('GatewayApp');
afterInit(server: Server) {
this.logger.log('Initiate Gateway');
}
handleConnection(client: Socket) {
client.emit('connection', 'Success from server');
this.logger.log(`connected ${client.id}`);
}
@SubscribeMessage('events')
handleEvent(@MessageBody() data: string): string {
this.logger.log(data);
return 'data recieved';
}
}
Finally I get This result
Image Result
Everything works fine :)
In case you want information of my certificate :
-----BEGIN CERTIFICATE-----
MIIECzCCAvOgAwIBAgIUICWr5H/qokSSpTlzE+tEnzgbkTcwDQYJKoZIhvcNAQEL
BQAwgZIxCzAJBgNVBAYTAlROMQ4wDAYDVQQIDAVUdW5pczEQMA4GA1UEBwwHTGUg
a3JhbTEUMBIGA1UECgwLbXMtdGVjaHNvZnQxCzAJBgNVBAsMAm1zMRIwEAYDVQQD
DAlkZXZlbG9wZXIxKjAoBgkqhkiG9w0BCQEWG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2gKfwEMREEFsUe9A6NOwnsZPIvATXDnN7QQgGyd5rOAqzOlZGl6UnoHwtVh
1xpYMMdjrkbnIpgxNlRYTSf8hqd4y2HAdZtpzfVLCQ==
-----END CERTIFICATE-----
Link for testing : https://8gwifi.org/PemParserFunctions.jsp
Just change **Sample file** to **crt** and copy my public key inside the box to get the informayion
My problem
When I give my local ip which is starts by 192.168.x.x to the client(android studio in same nework) we get time out failed to connectCould any one help me I'm stuck since one month
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
