Skip to content

Commit 37ce109

Browse files
authored
smp server: .well-known folder for server pages for SimpleX apps to handle preset server links (#1510)
* smp server: .well-known folder for server pages for SimpleX apps to handle preset server links * add short link group path * test
1 parent a66163d commit 37ce109

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"applinks": {
3+
"details": [
4+
{
5+
"appIDs": [
6+
"5NN7GUYB6T.chat.simplex.app"
7+
],
8+
"components": [
9+
{
10+
"/": "/contact/*"
11+
},
12+
{
13+
"/": "/contact"
14+
},
15+
{
16+
"/": "/invitation/*"
17+
},
18+
{
19+
"/": "/invitation"
20+
},
21+
{
22+
"/": "/a/*"
23+
},
24+
{
25+
"/": "/a"
26+
},
27+
{
28+
"/": "/c/*"
29+
},
30+
{
31+
"/": "/c"
32+
},
33+
{
34+
"/": "/g/*"
35+
},
36+
{
37+
"/": "/g"
38+
},
39+
{
40+
"/": "/i/*"
41+
},
42+
{
43+
"/": "/i"
44+
}
45+
]
46+
}
47+
]
48+
}
49+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"relation": [
4+
"delegate_permission/common.handle_all_urls"
5+
],
6+
"target": {
7+
"namespace": "android_app",
8+
"package_name": "chat.simplex.app",
9+
"sha256_cert_fingerprints": [
10+
"5E:3E:DC:C2:00:FB:A8:D5:F4:88:F3:CA:4C:32:5B:05:78:C5:6A:9C:03:A1:CC:B5:92:9C:D7:5C:7E:57:E2:4D",
11+
"3C:52:C4:FD:3C:AD:1C:07:C9:B0:0A:70:80:E3:58:FA:B9:FE:FC:B8:AF:5A:EC:14:77:65:F1:6D:0F:21:AD:85",
12+
"AE:C1:95:DC:FD:46:14:BD:3A:91:EC:26:D1:D5:14:C8:75:71:C5:CC:8D:CF:48:08:3F:92:83:14:3C:A2:B9:A6"
13+
]
14+
}
15+
}
16+
]

apps/smp-server/web/Static.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ generateSite :: ServerInformation -> Maybe TransportHost -> FilePath -> IO ()
8282
generateSite si onionHost sitePath = do
8383
createDirectoryIfMissing True sitePath
8484
B.writeFile (sitePath </> "index.html") $ serverInformation si onionHost
85-
createDirectoryIfMissing True $ sitePath </> "media"
86-
forM_ E.mediaContent $ \(path, bs) -> B.writeFile (sitePath </> "media" </> path) bs
85+
copyDir "media" E.mediaContent
86+
copyDir ".well-known" E.wellKnown
8787
createLinkPage "contact"
8888
createLinkPage "invitation"
8989
createLinkPage "a"
9090
createLinkPage "c"
9191
createLinkPage "i"
9292
logInfo $ "Generated static site contents at " <> tshow sitePath
9393
where
94+
copyDir dir content = do
95+
createDirectoryIfMissing True $ sitePath </> dir
96+
forM_ content $ \(path, s) -> do
97+
createDirectoryIfMissing True $ sitePath </> dir </> takeDirectory path
98+
B.writeFile (sitePath </> dir </> path) s
9499
createLinkPage path = do
95100
createDirectoryIfMissing True $ sitePath </> path
96101
B.writeFile (sitePath </> path </> "index.html") E.linkHtml

apps/smp-server/web/Static/Embedded.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ linkHtml = $(embedFile "apps/smp-server/static/link.html")
1313

1414
mediaContent :: [(FilePath, ByteString)]
1515
mediaContent = $(embedDir "apps/smp-server/static/media/")
16+
17+
wellKnown :: [(FilePath, ByteString)]
18+
wellKnown = $(embedDir "apps/smp-server/static/.well-known/")

tests/AgentTests/ConnectionRequestTests.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE OverloadedLists #-}
55
{-# LANGUAGE OverloadedStrings #-}
66
{-# LANGUAGE PatternSynonyms #-}
7+
{-# LANGUAGE ScopedTypeVariables #-}
78
{-# LANGUAGE TypeApplications #-}
89
{-# OPTIONS_GHC -Wno-orphans #-}
910
{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-}
@@ -332,6 +333,15 @@ connectionRequestTests =
332333
`shouldBe` contact shortSrv (LinkKey "0123456789abcdef0123456789abcdef")
333334
restoreShortLink [srv] (contact srv2 (LinkKey "0123456789abcdef0123456789abcdef"))
334335
`shouldBe` contact srv2 (LinkKey "0123456789abcdef0123456789abcdef")
336+
Right (lnk :: ConnShortLink 'CMContact) <- pure $ strDecode "https://localhost/a#4AkRDmhf64tdRlN406g8lJRg5OCmhD6ynIhi6glOcCM?p=7001&c=LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI"
337+
Right (lnk' :: ConnShortLink 'CMContact) <- pure $ strDecode "https://localhost/a#4AkRDmhf64tdRlN406g8lJRg5OCmhD6ynIhi6glOcCM"
338+
let presetSrv :: SMPServer = "smp://LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI=@localhost:7001"
339+
shortenShortLink [presetSrv] lnk `shouldBe` lnk'
340+
restoreShortLink [presetSrv] lnk' `shouldBe` lnk
341+
Right (inv :: ConnShortLink 'CMInvitation) <- pure $ strDecode "https://localhost/i#tnUaHYp8saREmyEHR93SBpl8ySHBchOt/LJ1ZQUzxH9Udb0jw5wmJACv5o6oe8e7BsX_hUCUMTSY?p=7001&c=LcJUMfVhwD8yxjAiSaDzzGF3-kLG4Uh0Fl_ZIjrRwjI"
342+
Right (inv' :: ConnShortLink 'CMInvitation) <- pure $ strDecode "https://localhost/i#tnUaHYp8saREmyEHR93SBpl8ySHBchOt/LJ1ZQUzxH9Udb0jw5wmJACv5o6oe8e7BsX_hUCUMTSY"
343+
shortenShortLink [presetSrv] inv `shouldBe` inv'
344+
restoreShortLink [presetSrv] inv' `shouldBe` inv
335345
where
336346
smpEncodingTest :: (Encoding a, Eq a, Show a, HasCallStack) => a -> Expectation
337347
smpEncodingTest a = smpDecode (smpEncode a) `shouldBe` Right a

0 commit comments

Comments
 (0)