Dovecot IMAPS . Port 993 , telnet NO IMAP handshake message but telnet port 143 does - postfix-mta

I am trying to setup a postfix/dovecot on ubuntu 20.x
After DOVECOT configuration I can connect(thru telnet, from my iPhone using gmail client) to port 143 and get IMAP handshake message, login etc.
BUT I get authentication failed error when connecting to port 993 (from iPhone)
then
I tried telnet 'mymailserver' 993 and get no IMAP handshake message..
Moreover, when i do openssl s_client -connect 'mailserver' 993 , I get the handshake message as expected..
Can someone help ?
Here is my dovecot -n
root#mail:/usr/share/dovecot/protocols.d# dovecot -n
# 2.3.7.2 (3c910f64b): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.5.7.2 ()
# OS: Linux 5.4.0-131-generic x86_64 Ubuntu 20.04.5 LTS
# Hostname: ****************
auth_mechanisms = plain login
auth_username_format = %n
mail_location = mbox:~/mail:INBOX=/var/mail/%u
mail_privileged_group = mail
namespace inbox {
inbox = yes
location =
mailbox Drafts {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
mailbox Trash {
special_use = \Trash
}
prefix =
}
passdb {
driver = pam
}
protocols = " imap lmtp pop3"
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
}
service imap-login {
inet_listener imap {
port = 143
}
inet_listener imaps {
port = 993
ssl = yes
}
}
service pop3-login {
inet_listener pop3 {
port = 110
}
inet_listener pop3s {
port = 995
ssl = yes
}
}
service submission-login {
inet_listener submission {
port = 587
}
}
ssl = required
ssl_cert = </etc/..../fullchain.pem
ssl_client_ca_dir = /etc/ssl/certs
ssl_dh = # hidden, use -P to show it
ssl_key = # hidden, use -P to show it
userdb {
driver = passwd
}

Related

Terraform not starting the nginx server on AWS

I am having the below terraform file where I am starting a Nginx server. Terraform is installing Nginx but the Nginx server did not start. I have to manually login to the ec2-machine and start the service. Where am i going wrong?
terraform {
required_version = ">=0.12, <0.13"
}
provider "aws" {
region = "ap-south-1"
}
resource "aws_instance" "ec2-instance" {
ami = "ami-04b2519c83e2a7ea5"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.web_security.id]
key_name = "kops-keypair"
user_data = <<-EOF
#!/bin/bash
sudo yum update -y
sudo yum install nginx -y
sudo service start nginx
EOF
tags = {
Name = "nginx-instance",
created-date = "22-04-2020"
}
}
resource "aws_security_group" "web_security" {
name = "web-security"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
My bad. The command should be sudo service nginx start

How do I switch SSL providers in MUP

In order to use Letsencrypt SSL in MUP I just use add a proxy in the config file:
proxy: {
domains: 'mydomain.com,www.mudomain.com',
ssl: {
// Enable let's encrypt to create free certificates.
// The email is used by Let's Encrypt to notify you when the
// certificates are close to expiring.
letsEncryptEmail: 'user#candidsky.com'
// forceSSL: true
}
},
The documentation is here
http://meteor-up.com/docs.html#ssl-support
But I can't find anything on how to use a custom SSL, I need to use comodo SSL.
Here is a way to do it
app: {
...
ssl: {
crt: './bundle.crt', // this is a bundle of certificates
key: './private.key', // this is the private key of the certificate
port: 443 // 443 is the default value and it's the standard HTTPS port
}
...
}
Note that you also can set pem key in the key field.
http://meteor-up.com/docs.html#ssl-support

nginx upstream for red:connect() at lua-resty-redis

I need to switch between pre-configured upstream of redis servers and dynamic IP:6379 by custom header for testing purpose. Current config sample:
upstream backend_cluster {
server aaa.bbb.ccc.ddd:6379 fail_timeout=0 max_fails=0;
server aaa.bbb.ccc.ddd:6380 fail_timeout=0 max_fails=0;
server aaa.bbb.ccc.ddd:6381 fail_timeout=0 max_fails=0;
server aaa.bbb.ccc.ddd:6382 fail_timeout=0 max_fails=0;
keepalive 16;
}
map $http_BackendIP $backend_upstream {
default "backend_cluster";
"~^([0-9]{1,3}[\.]){3}[0-9]{1,3}+" "$BackendIP";
}
server {
listen 80 default_server;
server_name _;
set $BackendIP "${http_BackendIP}:6379";
location = /test {
........
content_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000)
local ok, err = red:connect(ngx.var.backend_upstream)
if not ok then
ngx.log(ngx.ERR, "failed to connect: ", err)
return
end
ok, err = red:rpush(ngx.var.redis_key, ngx.var.query)
if not ok then
ngx.log(ngx.ERR, "rpush error: ", err)
return
end
}
}
}
This config successfully push data to redis at 123.456.789.0:6379, if I set custom header to
"BackendIP: 123.456.789.0"
but without BackendIP header it fails to understand nginx upstream with errors:
** failed to connect: backend_cluster could not be resolved (3: Host not found) **
Can I somehow make that thing work as expected? Thanks in advance, comrades.

Transfer UDP socket in node.js from Application to HTTP

Is it possible to transfer a Socket coming from a application to http via NodeJS?
I send my socket with a application (in c++) in UDP or TCP(if impossible in UDP...) to NodeJS.
My script from NodeJS:
var server = dgram.createSocket("udp4");
server.on("message", function (content, rinfo)
{
console.log("socket: " + content + " from " + rinfo.address + ":" + rinfo.port); });
server.on("listening", function () {
});
server.bind(7788);
Up to now does that function, but then how to transfer my socket to Socket.io for example?
I would like to send the socket to Socket.io (for example) for transfer the socket to HTTP. By using a function like this for example, but without renew a establishing a connection to socket.io :
io.sockets.on('connection', function (socket) {
socket.emit(content);
});
Thanks you for your help.
++ Metra.
Here's a complete example with a socket.io server, a web server sending out a very simple page (it will just log all messages to console) and an UDP socket listening for messages, passing them to all connected clients:
var http = require('http'),
dgram = require('dgram'),
socketio = require('socket.io');
var app = http.createServer(handleRequest),
io = socketio.listen(app),
socket = dgram.createSocket('udp4');
socket.on('message', function(content, rinfo) {
console.log('got message', content, 'from', rinfo.address, rinfo.port);
io.sockets.emit('udp message', content.toString());
});
function handleRequest(req, res) {
res.writeHead(200, {'content-type': 'text/html'});
res.end("<!doctype html> \
<html><head> \
<script src='/socket.io/socket.io.js'></script> \
<script> \
var socket = io.connect('localhost', {port: 8000}); \
socket.on('udp message', function(message) { console.log(message) }); \
</script></head></html>");
}
socket.bind(7788);
app.listen(8000);
Update: As io.sockets.emit shows, all messages received on the UDP port 7788 are sent to all connected clients. If you want to route them based on some data in the message or similar, you could use Socket.IO's "room" feature: io.sockets.of(someRoom).emit. In the connection handler for Socket.IO, you can join each client to some room.

HTTPS Proxy Server in node.js

I am developing a node.js proxy server application and I want it to support HTTP and HTTPS(SSL) protocols (as server).
I'm currently using node-http-proxy like this:
const httpProxy = require('http-proxy'),
http = require('http');
var server = httpProxy.createServer(9000, 'localhost', function(req, res, proxy) {
console.log(req.url);
proxy.proxyRequest(req, res);
});
http.createServer(function(req, res) {
res.end('hello!');
}).listen(9000);
server.listen(8000);
I setup my browser to use HTTP proxy on localhost:8000 and it works. I also want to catch HTTPS requests (ie. setup my browser to use localhost:8000 as HTTPS proxy as well and catch the requests in my application). Could you please help me how can I do that?
PS:
If I subscribe to upgrade event of httpProxy server object I can get the requests but I don't know how to forward the request and send response to client:
server.on('upgrade', function(req, socket, head) {
console.log(req.url);
// I don't know how to forward the request and send the response to client
});
Any helps would be appreciated.
Solutions barely exist for this, and the documentation is poor at best for supporting both on one server. The trick here is to understand that client proxy configurations may send https requests to an http proxy server. This is true for Firefox if you specify an HTTP proxy and then check "same for all protocols".
You can handle https connections sent to an HTTP server by listening for the "connect" event. Note that you won't have access to the response object on the connect event, only the socket and bodyhead. Data sent over this socket will remain encrypted to you as the proxy server.
In this solution, you don't have to make your own certificates, and you won't have certificate conflicts as a result. The traffic is simply proxied, not intercepted and rewritten with different certificates.
// Install npm dependencies first
// npm init
// npm install --save url#0.10.3
// npm install --save http-proxy#1.11.1
var httpProxy = require("http-proxy");
var http = require("http");
var url = require("url");
var net = require('net');
var server = http.createServer(function (req, res) {
var urlObj = url.parse(req.url);
var target = urlObj.protocol + "//" + urlObj.host;
console.log("Proxy HTTP request for:", target);
var proxy = httpProxy.createProxyServer({});
proxy.on("error", function (err, req, res) {
console.log("proxy error", err);
res.end();
});
proxy.web(req, res, {target: target});
}).listen(8080); //this is the port your clients will connect to
var regex_hostport = /^([^:]+)(:([0-9]+))?$/;
var getHostPortFromString = function (hostString, defaultPort) {
var host = hostString;
var port = defaultPort;
var result = regex_hostport.exec(hostString);
if (result != null) {
host = result[1];
if (result[2] != null) {
port = result[3];
}
}
return ( [host, port] );
};
server.addListener('connect', function (req, socket, bodyhead) {
var hostPort = getHostPortFromString(req.url, 443);
var hostDomain = hostPort[0];
var port = parseInt(hostPort[1]);
console.log("Proxying HTTPS request for:", hostDomain, port);
var proxySocket = new net.Socket();
proxySocket.connect(port, hostDomain, function () {
proxySocket.write(bodyhead);
socket.write("HTTP/" + req.httpVersion + " 200 Connection established\r\n\r\n");
}
);
proxySocket.on('data', function (chunk) {
socket.write(chunk);
});
proxySocket.on('end', function () {
socket.end();
});
proxySocket.on('error', function () {
socket.write("HTTP/" + req.httpVersion + " 500 Connection error\r\n\r\n");
socket.end();
});
socket.on('data', function (chunk) {
proxySocket.write(chunk);
});
socket.on('end', function () {
proxySocket.end();
});
socket.on('error', function () {
proxySocket.end();
});
});
Here is my NO-dependencies solution (pure NodeJS system libraries):
const http = require('http')
const port = process.env.PORT || 9191
const net = require('net')
const url = require('url')
const requestHandler = (req, res) => { // discard all request to proxy server except HTTP/1.1 CONNECT method
res.writeHead(405, {'Content-Type': 'text/plain'})
res.end('Method not allowed')
}
const server = http.createServer(requestHandler)
const listener = server.listen(port, (err) => {
if (err) {
return console.error(err)
}
const info = listener.address()
console.log(`Server is listening on address ${info.address} port ${info.port}`)
})
server.on('connect', (req, clientSocket, head) => { // listen only for HTTP/1.1 CONNECT method
console.log(clientSocket.remoteAddress, clientSocket.remotePort, req.method, req.url)
if (!req.headers['proxy-authorization']) { // here you can add check for any username/password, I just check that this header must exist!
clientSocket.write([
'HTTP/1.1 407 Proxy Authentication Required',
'Proxy-Authenticate: Basic realm="proxy"',
'Proxy-Connection: close',
].join('\r\n'))
clientSocket.end('\r\n\r\n') // empty body
return
}
const {port, hostname} = url.parse(`//${req.url}`, false, true) // extract destination host and port from CONNECT request
if (hostname && port) {
const serverErrorHandler = (err) => {
console.error(err.message)
if (clientSocket) {
clientSocket.end(`HTTP/1.1 500 ${err.message}\r\n`)
}
}
const serverEndHandler = () => {
if (clientSocket) {
clientSocket.end(`HTTP/1.1 500 External Server End\r\n`)
}
}
const serverSocket = net.connect(port, hostname) // connect to destination host and port
const clientErrorHandler = (err) => {
console.error(err.message)
if (serverSocket) {
serverSocket.end()
}
}
const clientEndHandler = () => {
if (serverSocket) {
serverSocket.end()
}
}
clientSocket.on('error', clientErrorHandler)
clientSocket.on('end', clientEndHandler)
serverSocket.on('error', serverErrorHandler)
serverSocket.on('end', serverEndHandler)
serverSocket.on('connect', () => {
clientSocket.write([
'HTTP/1.1 200 Connection Established',
'Proxy-agent: Node-VPN',
].join('\r\n'))
clientSocket.write('\r\n\r\n') // empty body
// "blindly" (for performance) pipe client socket and destination socket between each other
serverSocket.pipe(clientSocket, {end: false})
clientSocket.pipe(serverSocket, {end: false})
})
} else {
clientSocket.end('HTTP/1.1 400 Bad Request\r\n')
clientSocket.destroy()
}
})
I tested this code with Firefox Proxy Settings (it even asks for username and password!). I entered IP address of machine where this code is runned and 9191 port as you can see in the code. I also set "Use this proxy server for all protocols". I run this code locally and on VPS - in both cases works!
You can test your NodeJS proxy with curl:
curl -x http://username:password#127.0.0.1:9191 https://www.google.com/
I have created a http/https proxy with the aid of the http-proxy module: https://gist.github.com/ncthis/6863947
Code as of now:
var fs = require('fs'),
http = require('http'),
https = require('https'),
httpProxy = require('http-proxy');
var isHttps = true; // do you want a https proxy?
var options = {
https: {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('key-cert.pem')
}
};
// this is the target server
var proxy = new httpProxy.HttpProxy({
target: {
host: '127.0.0.1',
port: 8080
}
});
if (isHttps)
https.createServer(options.https, function(req, res) {
console.log('Proxying https request at %s', new Date());
proxy.proxyRequest(req, res);
}).listen(443, function(err) {
if (err)
console.log('Error serving https proxy request: %s', req);
console.log('Created https proxy. Forwarding requests from %s to %s:%s', '443', proxy.target.host, proxy.target.port);
});
else
http.createServer(options.https, function(req, res) {
console.log('Proxying http request at %s', new Date());
console.log(req);
proxy.proxyRequest(req, res);
}).listen(80, function(err) {
if (err)
console.log('Error serving http proxy request: %s', req);
console.log('Created http proxy. Forwarding requests from %s to %s:%s', '80', proxy.target.host, proxy.target.port);
});
The node-http-proxy docs contain examples of this. Look for "Proxying to HTTPS from HTTPS" at https://github.com/nodejitsu/node-http-proxy The configuration process is slightly different in every browser. Some have the option to use your proxy settings for all protocols; some you need to configure the SSL proxy separately.

Resources