@@ -44,13 +44,9 @@ export default function Loon_Producer() {
4444 return hysteria2 ( proxy ) ;
4545 }
4646 if ( proxy . type === 'anytls' ) {
47- if (
48- proxy . network &&
49- ( ! [ 'tcp' ] . includes ( proxy . network ) ||
50- ( [ 'tcp' ] . includes ( proxy . network ) && proxy [ 'reality-opts' ] ) )
51- ) {
47+ if ( proxy . network && ! [ 'tcp' ] . includes ( proxy . network ) ) {
5248 throw new Error (
53- `Platform ${ targetPlatform } does not support proxy type ${ proxy . type } with network or REALITY ` ,
49+ `Platform ${ targetPlatform } does not support proxy type ${ proxy . type } with network ${ proxy . network } ` ,
5450 ) ;
5551 }
5652
@@ -73,6 +69,18 @@ function appendAlpn(result, proxy) {
7369 if ( alpn ) result . append ( `,alpn="${ alpn } "` ) ;
7470}
7571
72+ function appendReality ( result , proxy ) {
73+ result . appendIfPresent ( `,sni=${ proxy . sni } ` , 'sni' ) ;
74+ result . appendIfPresent (
75+ `,public-key="${ proxy [ 'reality-opts' ] [ 'public-key' ] } "` ,
76+ 'reality-opts.public-key' ,
77+ ) ;
78+ result . appendIfPresent (
79+ `,short-id=${ proxy [ 'reality-opts' ] [ 'short-id' ] } ` ,
80+ 'reality-opts.short-id' ,
81+ ) ;
82+ }
83+
7684function getLoonAlpn ( proxy ) {
7785 const values = Array . isArray ( proxy . alpn )
7886 ? proxy . alpn
@@ -134,14 +142,6 @@ function shadowsocks(proxy) {
134142 // obfs
135143 if ( isPresent ( proxy , 'plugin' ) ) {
136144 if ( proxy . plugin === 'obfs' ) {
137- if (
138- proxy [ 'plugin-opts' ] ?. mode &&
139- proxy . cipher . startsWith ( '2022-' )
140- ) {
141- throw new Error (
142- `${ proxy . cipher } ${ proxy . plugin } is not supported` ,
143- ) ;
144- }
145145 result . append ( `,obfs-name=${ proxy [ 'plugin-opts' ] . mode } ` ) ;
146146 result . appendIfPresent (
147147 `,obfs-host=${ proxy [ 'plugin-opts' ] . host } ` ,
@@ -311,6 +311,7 @@ function shadowsocksr(proxy) {
311311}
312312
313313function trojan ( proxy ) {
314+ const isReality = ! ! proxy [ 'reality-opts' ] ;
314315 const result = new Result ( proxy ) ;
315316 result . append (
316317 `${ proxy . name } =trojan,${ proxy . server } ,${ proxy . port } ,"${ proxy . password } "` ,
@@ -343,16 +344,20 @@ function trojan(proxy) {
343344 appendTlsProfile ( result , proxy ) ;
344345 appendAlpn ( result , proxy ) ;
345346
346- // sni
347- result . appendIfPresent ( `,tls-name=${ proxy . sni } ` , 'sni' ) ;
348- result . appendIfPresent (
349- `,tls-cert-sha256=${ proxy [ 'tls-fingerprint' ] } ` ,
350- 'tls-fingerprint' ,
351- ) ;
352- result . appendIfPresent (
353- `,tls-pubkey-sha256=${ proxy [ 'tls-pubkey-sha256' ] } ` ,
354- 'tls-pubkey-sha256' ,
355- ) ;
347+ if ( isReality ) {
348+ appendReality ( result , proxy ) ;
349+ } else {
350+ // sni
351+ result . appendIfPresent ( `,tls-name=${ proxy . sni } ` , 'sni' ) ;
352+ result . appendIfPresent (
353+ `,tls-cert-sha256=${ proxy [ 'tls-fingerprint' ] } ` ,
354+ 'tls-fingerprint' ,
355+ ) ;
356+ result . appendIfPresent (
357+ `,tls-pubkey-sha256=${ proxy [ 'tls-pubkey-sha256' ] } ` ,
358+ 'tls-pubkey-sha256' ,
359+ ) ;
360+ }
356361
357362 // tfo
358363 result . appendIfPresent ( `,fast-open=${ proxy . tfo } ` , 'tfo' ) ;
@@ -375,6 +380,7 @@ function trojan(proxy) {
375380}
376381
377382function anytls ( proxy ) {
383+ const isReality = ! ! proxy [ 'reality-opts' ] ;
378384 const result = new Result ( proxy ) ;
379385 result . append (
380386 `${ proxy . name } =anytls,${ proxy . server } ,${ proxy . port } ,"${ proxy . password } "` ,
@@ -400,16 +406,20 @@ function anytls(proxy) {
400406 appendTlsProfile ( result , proxy ) ;
401407 appendAlpn ( result , proxy ) ;
402408
403- // sni
404- result . appendIfPresent ( `,tls-name=${ proxy . sni } ` , 'sni' ) ;
405- result . appendIfPresent (
406- `,tls-cert-sha256=${ proxy [ 'tls-fingerprint' ] } ` ,
407- 'tls-fingerprint' ,
408- ) ;
409- result . appendIfPresent (
410- `,tls-pubkey-sha256=${ proxy [ 'tls-pubkey-sha256' ] } ` ,
411- 'tls-pubkey-sha256' ,
412- ) ;
409+ if ( isReality ) {
410+ appendReality ( result , proxy ) ;
411+ } else {
412+ // sni
413+ result . appendIfPresent ( `,tls-name=${ proxy . sni } ` , 'sni' ) ;
414+ result . appendIfPresent (
415+ `,tls-cert-sha256=${ proxy [ 'tls-fingerprint' ] } ` ,
416+ 'tls-fingerprint' ,
417+ ) ;
418+ result . appendIfPresent (
419+ `,tls-pubkey-sha256=${ proxy [ 'tls-pubkey-sha256' ] } ` ,
420+ 'tls-pubkey-sha256' ,
421+ ) ;
422+ }
413423
414424 // tfo
415425 result . appendIfPresent ( `,fast-open=${ proxy . tfo } ` , 'tfo' ) ;
@@ -487,15 +497,7 @@ function vmess(proxy) {
487497 }
488498
489499 if ( isReality ) {
490- result . appendIfPresent ( `,sni=${ proxy . sni } ` , 'sni' ) ;
491- result . appendIfPresent (
492- `,public-key="${ proxy [ 'reality-opts' ] [ 'public-key' ] } "` ,
493- 'reality-opts.public-key' ,
494- ) ;
495- result . appendIfPresent (
496- `,short-id=${ proxy [ 'reality-opts' ] [ 'short-id' ] } ` ,
497- 'reality-opts.short-id' ,
498- ) ;
500+ appendReality ( result , proxy ) ;
499501 } else {
500502 // sni
501503 result . appendIfPresent ( `,tls-name=${ proxy . sni } ` , 'sni' ) ;
@@ -604,15 +606,7 @@ function vless(proxy) {
604606 result . appendIfPresent ( `,flow=${ proxy . flow } ` , 'flow' ) ;
605607 }
606608 if ( isReality ) {
607- result . appendIfPresent ( `,sni=${ proxy . sni } ` , 'sni' ) ;
608- result . appendIfPresent (
609- `,public-key="${ proxy [ 'reality-opts' ] [ 'public-key' ] } "` ,
610- 'reality-opts.public-key' ,
611- ) ;
612- result . appendIfPresent (
613- `,short-id=${ proxy [ 'reality-opts' ] [ 'short-id' ] } ` ,
614- 'reality-opts.short-id' ,
615- ) ;
609+ appendReality ( result , proxy ) ;
616610 } else {
617611 // sni
618612 result . appendIfPresent ( `,tls-name=${ proxy . sni } ` , 'sni' ) ;
0 commit comments