Skip to content

Commit

Permalink
g3-dpi: add port for On-Demand Mail Relay protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed May 15, 2024
1 parent ca80f9d commit 2a64efc
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ The code should comply to these, but should be more compliant to existing popula
: Simple Mail Transfer Protocol
- [rfc6409](https://datatracker.ietf.org/doc/html/rfc6409)
: Message Submission for Mail
- [rfc2645](https://datatracker.ietf.org/doc/html/rfc2645)
: ON-DEMAND MAIL RELAY (ODMR) SMTP with Dynamic IP Addresses
- [rfc6152](https://datatracker.ietf.org/doc/html/rfc6152)
: SMTP Service Extension for 8-bit MIME Transport
- [rfc3030](https://datatracker.ietf.org/doc/html/rfc3030)
Expand Down
1 change: 1 addition & 0 deletions g3proxy/src/inspect/smtp/initiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl Initiation {
"RRVS" => true, // Require Recipient Valid Since, RFC7293, add a RCPT param key
"REQUIRETLS" => true, // Require TLS, RFC8689, add a MAIL param key
"LIMITS" => true, // LIMITS, RFC9422
"ATRN" => true, // On-Demand Mail Relay, RFC2645, change the protocol
_ => false,
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/g3-dpi/src/protocol/bittorrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl ProtocolInspectState {
self.exclude_other(MaybeProtocol::Ftp);
self.exclude_other(MaybeProtocol::Ssh);
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);
self.exclude_other(MaybeProtocol::Pop3);
self.exclude_other(MaybeProtocol::Imap);
self.exclude_other(MaybeProtocol::Http);
Expand Down
2 changes: 2 additions & 0 deletions lib/g3-dpi/src/protocol/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl ProtocolInspectState {
// 0x31
self.ftp_exclude_by_byte0();
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);
self.exclude_other(MaybeProtocol::Nntp);

if &data[0..3] == b"120" {
Expand All @@ -63,6 +64,7 @@ impl ProtocolInspectState {
// 0x34
self.ftp_exclude_by_byte0();
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);
self.exclude_other(MaybeProtocol::Nntp);

if &data[0..3] == b"421" {
Expand Down
1 change: 1 addition & 0 deletions lib/g3-dpi/src/protocol/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl ProtocolInspectState {
self.exclude_other(MaybeProtocol::Ftp);
self.exclude_other(MaybeProtocol::Ssh);
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);
self.exclude_other(MaybeProtocol::Pop3);
self.exclude_other(MaybeProtocol::Nntp);
self.exclude_other(MaybeProtocol::Nats);
Expand Down
3 changes: 2 additions & 1 deletion lib/g3-dpi/src/protocol/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl ProtocolInspectState {
MaybeProtocol::BitTorrent => self.check_bittorrent_tcp_handshake(data),
MaybeProtocol::Ftp
| MaybeProtocol::Smtp
| MaybeProtocol::Odmr
| MaybeProtocol::Pop3
| MaybeProtocol::Nntp
| MaybeProtocol::Nnsp
Expand Down Expand Up @@ -147,7 +148,7 @@ impl ProtocolInspectState {
match proto {
MaybeProtocol::Ftp => self.check_ftp_server_greeting(data, size_limit),
MaybeProtocol::Ssh => self.check_ssh_server_protocol_version_exchange(data),
MaybeProtocol::Smtp => self.check_smtp_server_greeting(data),
MaybeProtocol::Smtp | MaybeProtocol::Odmr => self.check_smtp_server_greeting(data),
MaybeProtocol::Pop3 => self.check_pop3_server_greeting(data),
MaybeProtocol::Nntp | MaybeProtocol::Nnsp => self.check_nntp_server_greeting(data),
MaybeProtocol::Imap => self.check_imap_server_greeting(data, size_limit),
Expand Down
2 changes: 2 additions & 0 deletions lib/g3-dpi/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub use portmap::{ProtocolPortMap, ProtocolPortMapValue};
pub enum MaybeProtocol {
Http,
Smtp,
Odmr, // On-Demand Mail Relay, a restricted profile of SMTP
Ssh,
Ftp,
Dns,
Expand Down Expand Up @@ -88,6 +89,7 @@ impl FromStr for MaybeProtocol {
match s.to_lowercase().as_str() {
"http" => Ok(MaybeProtocol::Http),
"smtp" => Ok(MaybeProtocol::Smtp),
"odmr" => Ok(MaybeProtocol::Odmr),
"ssh" => Ok(MaybeProtocol::Ssh),
"ftp" => Ok(MaybeProtocol::Ftp),
"pop3" => Ok(MaybeProtocol::Pop3),
Expand Down
1 change: 1 addition & 0 deletions lib/g3-dpi/src/protocol/nats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl ProtocolInspectState {
self.exclude_other(MaybeProtocol::Ftp);
self.exclude_other(MaybeProtocol::Ssh);
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);
self.exclude_other(MaybeProtocol::Pop3);
self.exclude_other(MaybeProtocol::Nntp);
self.exclude_other(MaybeProtocol::Imap);
Expand Down
1 change: 1 addition & 0 deletions lib/g3-dpi/src/protocol/nntp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl ProtocolInspectState {
// exclude impossible protocols
self.exclude_other(MaybeProtocol::Ftp);
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);

if !matches!(data[2], b'0' | b'1') {
self.exclude_current();
Expand Down
1 change: 1 addition & 0 deletions lib/g3-dpi/src/protocol/pop3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl ProtocolInspectState {
self.exclude_other(MaybeProtocol::Ftp);
self.exclude_other(MaybeProtocol::Ssh);
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);
self.exclude_other(MaybeProtocol::Nntp);
self.exclude_other(MaybeProtocol::Imap);
self.exclude_other(MaybeProtocol::Nats);
Expand Down
1 change: 1 addition & 0 deletions lib/g3-dpi/src/protocol/portmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl ProtocolPortMap {
map.insert(119, MaybeProtocol::Nntp);
map.insert(143, MaybeProtocol::Imap);
map.insert(322, MaybeProtocol::Rtsps);
map.insert(366, MaybeProtocol::Odmr);
map.insert(433, MaybeProtocol::Nnsp);
map.insert(443, MaybeProtocol::Https);
map.insert(465, MaybeProtocol::Submissions);
Expand Down
1 change: 1 addition & 0 deletions lib/g3-dpi/src/protocol/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl ProtocolInspectState {
// exclude impossible protocols
self.exclude_other(MaybeProtocol::Ftp);
self.exclude_other(MaybeProtocol::Smtp);
self.exclude_other(MaybeProtocol::Odmr);
self.exclude_other(MaybeProtocol::Pop3);
self.exclude_other(MaybeProtocol::Nntp);
self.exclude_other(MaybeProtocol::Imap);
Expand Down

0 comments on commit 2a64efc

Please sign in to comment.