Skip to content

Commit a76fd4c

Browse files
committed
ssl server option
1 parent 3405783 commit a76fd4c

File tree

5 files changed

+98
-5
lines changed

5 files changed

+98
-5
lines changed

Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ fien-server:
122122
.PHONY: opusMT-server opusMT-router
123123
opusMT-server: install-marian-server install-opusMT-server
124124
opusMT-router: install-opusMT-router
125+
opusMT-ssl-router: install-opusMT-ssl-router
125126

126127

127128
.PHONY: install-marian-server install-opusMT-server
128129
install-marian-server: /etc/init.d/marian-${DATASET}-${LANGPAIR}
129130
install-opusMT-server: /etc/init.d/opusMT-${DATASET}-${LANGPAIR}
130131
install-opusMT-router: /etc/init.d/opusMT
132+
install-opusMT-ssl-router: /etc/init.d/opusMT_SSL
131133

132134
# install-marian-server: /etc/init/marian-${DATASET}-${LANGPAIR}.conf
133135
# install-opusMT-server: /etc/init/opusMT-${DATASET}-${LANGPAIR}.conf
@@ -195,6 +197,27 @@ model-list.txt:
195197
service ${notdir $@} restart
196198

197199

200+
/etc/ssl/opusMT/cert.pem:
201+
mkdir -p $(dir $@)
202+
openssl req -new -x509 -days 365 -nodes -out $@ -keyout ${dir $@}key.pem
203+
204+
/etc/init.d/opusMT_SSL: ${OPUSMT_ROUTER} ${OPUSMT_CONFIG} /etc/ssl/opusMT/cert.pem service-template
205+
sed -e 's#%%SERVICENAME%%#opusMT#' \
206+
-e 's#%%APPSHORTDESCR%%#opusMT#' \
207+
-e 's#%%APPLONGDESCR%%#translation service#' \
208+
-e 's#%%APPBIN%%#$<#' \
209+
-e 's#%%APPARGS%%#-p ${ROUTER_PORT} -c ${OPUSMT_CONFIG} -s ${DEFAULT_SOURCE_LANG} -t ${DEFAULT_TARGET_LANG} --ssl 1 --cert /etc/ssl/opusMT/cert.pem --key /etc/ssl/opusMT/key.pem --port 443#' \
210+
< service-template > ${notdir $@}
211+
mkdir -p ${dir ${OPUSMT_CACHE}}
212+
${INSTALL_BIN} ${notdir $@} $@
213+
rm -f ${notdir $@}
214+
update-rc.d ${notdir $@} defaults 80
215+
rm -f ${notdir $@}
216+
service ${notdir $@} restart
217+
218+
219+
220+
198221
## opusMT service via sysvinit
199222
/etc/init.d/opusMT-${DATASET}-${LANGPAIR}: ${OPUSMT_SERVER} service-template ${APPLYBPE}
200223
if [ -e ${BPEMODEL} ]; then \

hf/Makefile

+43-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,48 @@
7575
# https://object.pouta.csc.fi/Tatoeba-MT-models/zlw-zle/opusTCv20210807+bt_transformer-big_2022-03-19.zip
7676

7777

78-
MARIAN_MODEL_URLS =
78+
## done for English-xxx both directions (big transformer)
79+
80+
# https://object.pouta.csc.fi/Tatoeba-MT-models/eng-fin/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
81+
# https://object.pouta.csc.fi/Tatoeba-MT-models/zle-eng/opusTCv20210807+bt_transformer-big_2022-03-17.zip \
82+
# https://object.pouta.csc.fi/Tatoeba-MT-models/eng-zle/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
83+
84+
MARIAN_MODEL_URLS = \
85+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-ara/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
86+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-bul/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
87+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-cat+oci+spa/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
88+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-ces+slk/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
89+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-ell/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
90+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-est/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
91+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-fra/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
92+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-gmq/opusTCv20210807+bt_transformer-big_2022-03-17.zip \
93+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-hun/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
94+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-ita/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
95+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-lav/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
96+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-lit/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
97+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-por/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
98+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-ron/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
99+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-spa/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
100+
https://object.pouta.csc.fi/Tatoeba-MT-models/eng-tur/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
101+
https://object.pouta.csc.fi/Tatoeba-MT-models/ara-eng/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
102+
https://object.pouta.csc.fi/Tatoeba-MT-models/bul-eng/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
103+
https://object.pouta.csc.fi/Tatoeba-MT-models/cat+oci+spa-eng/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
104+
https://object.pouta.csc.fi/Tatoeba-MT-models/cel-eng/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
105+
https://object.pouta.csc.fi/Tatoeba-MT-models/ces+slk-eng/opusTCv20210807+bt_transformer-big_2022-03-17.zip \
106+
https://object.pouta.csc.fi/Tatoeba-MT-models/ell-eng/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
107+
https://object.pouta.csc.fi/Tatoeba-MT-models/est-eng/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
108+
https://object.pouta.csc.fi/Tatoeba-MT-models/fra-eng/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
109+
https://object.pouta.csc.fi/Tatoeba-MT-models/gmq-eng/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
110+
https://object.pouta.csc.fi/Tatoeba-MT-models/hbs-eng/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
111+
https://object.pouta.csc.fi/Tatoeba-MT-models/heb-eng/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
112+
https://object.pouta.csc.fi/Tatoeba-MT-models/hun-eng/opusTCv20210807+bt_transformer-big_2022-03-09.zip \
113+
https://object.pouta.csc.fi/Tatoeba-MT-models/ita-eng/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
114+
https://object.pouta.csc.fi/Tatoeba-MT-models/lav-eng/opusTCv20210807+bt_transformer-big_2022-03-13.zip \
115+
https://object.pouta.csc.fi/Tatoeba-MT-models/lit-eng/opusTCv20210807+bt_transformer-big_2022-02-25.zip \
116+
https://object.pouta.csc.fi/Tatoeba-MT-models/tur-eng/opusTCv20210807+bt_transformer-big_2022-03-17.zip \
117+
https://object.pouta.csc.fi/Tatoeba-MT-models/zls-eng/opusTCv20210807+bt_transformer-big_2022-03-17.zip \
118+
https://object.pouta.csc.fi/Tatoeba-MT-models/zlw-eng/opusTCv20210807+bt_transformer-big_2022-03-17.zip
119+
79120

80121
SHELL := bash
81122

@@ -485,7 +526,7 @@ endif
485526

486527

487528

488-
## OLD: extract becnhmark scores
529+
## OLD: extract benchmark scores
489530

490531
# ifeq (${shell wget -q -O - ${SCORES_FILE} | head -3 | wc -l | xargs},3)
491532
# @echo '* additional benchmark results: [${notdir ${SCORES_FILE}}](${SCORES_FILE})' >> $@

opusMT-client.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function, unicode_literals, division
44

55
import sys
6+
import ssl
67
import time
78
import argparse
89
import json
@@ -20,10 +21,17 @@
2021
parser.add_argument("-s", "--source-language", type=str, default='detect')
2122
parser.add_argument("-t", "--target-language", type=str, default='en')
2223
parser.add_argument("-m", "--model", type=str, default='default')
24+
parser.add_argument("--ssl", default=0, type=int, action="store", dest="ssl",
25+
help="ssl (1: on, 0: off (default))")
26+
2327
args = parser.parse_args()
2428

2529
# open connection
26-
ws = create_connection("ws://{}:{}/translate".format(args.host,args.port))
30+
if args.ssl == 1:
31+
ws = create_connection("wss://{}:{}/translate".format(args.host,args.port), sslopt={"cert_reqs": ssl.CERT_NONE})
32+
33+
else:
34+
ws = create_connection("ws://{}:{}/translate".format(args.host,args.port))
2735

2836
count = 0
2937
batch = ""

opusMT-router.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
import signal
77
import sys
8+
import ssl
89
import argparse
910
import codecs
1011
import json
1112
# import socket
1213
from websocket import create_connection
13-
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
14+
from SimpleWebSocketServer import SimpleWebSocketServer, SimpleSSLWebSocketServer, WebSocket
1415

1516
## language identifer (if source language is not given)
1617
import pycld2 as cld2
@@ -27,6 +28,16 @@
2728
parser.add_argument('-m','--max-input-length', type=int, default=1000,
2829
help='maximum length of the input string')
2930

31+
## SSL options
32+
parser.add_argument("--ssl", default=0, type=int, action="store", dest="ssl",
33+
help="ssl (1: on, 0: off (default))")
34+
parser.add_argument("--cert", default='./cert.pem', type=str, action="store", dest="cert",
35+
help="cert (./cert.pem)")
36+
parser.add_argument("--key", default='./key.pem', type=str, action="store", dest="key",
37+
help="key (./key.pem)")
38+
parser.add_argument("--ver", default=ssl.PROTOCOL_TLSv1_2, type=int, action="store", dest="ver",
39+
help="ssl version")
40+
3041

3142
args = parser.parse_args()
3243

@@ -146,5 +157,11 @@ def handleConnected(self):
146157
def handleClose(self):
147158
print(self.address, 'closed')
148159

149-
server = SimpleWebSocketServer('', args.port, Translate)
160+
161+
if args.ssl == 1:
162+
print("open ssl connection with version " + str(args.ver))
163+
server = SimpleSSLWebSocketServer('', args.port, Translate,
164+
args.cert, args.key, version=args.ver)
165+
else:
166+
server = SimpleWebSocketServer('', args.port, Translate)
150167
server.serveforever()

uh/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ UH_MODEL_CONFIG = opusMT-servers-UH.json
1010
opusMT-UH: ${SHAREDIR}/opusMT/${UH_MODEL_CONFIG}
1111
${MAKE} -C .. OPUSMT_CONFIG=$< opusMT-router
1212

13+
.PHONY: opusMT-UH-SSL
14+
opusMT-UH-SSL: ${SHAREDIR}/opusMT/${UH_MODEL_CONFIG}
15+
${MAKE} -C .. OPUSMT_CONFIG=$< opusMT-ssl-router
16+
1317

1418
## short-cut targets for installing MT-services for other language pairs
1519
enfi-server:

0 commit comments

Comments
 (0)