{"id":26891061,"url":"https://github.com/tagaryen/archer-net","last_synced_at":"2025-05-12T13:04:37.336Z","repository":{"id":266389177,"uuid":"898203353","full_name":"tagaryen/archer-net","owner":"tagaryen","description":"network written with java and c, to support latest openssl(gmssl) 1.3, support SM2_WITH_SM3(encryptCrt and encryptKey) TLS etc.","archived":false,"fork":false,"pushed_at":"2025-03-28T07:56:01.000Z","size":11032,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T08:33:46.669Z","etag":null,"topics":["encrypt-certificates","gmssl","http","libevent","networking","openssl","sm2"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tagaryen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-04T01:13:32.000Z","updated_at":"2025-03-28T07:56:05.000Z","dependencies_parsed_at":"2025-03-10T03:35:16.291Z","dependency_job_id":"981232ea-2819-475c-8cb0-809dcece3b24","html_url":"https://github.com/tagaryen/archer-net","commit_stats":null,"previous_names":["tagaryen/archer-net"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagaryen%2Farcher-net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagaryen%2Farcher-net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagaryen%2Farcher-net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tagaryen%2Farcher-net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tagaryen","download_url":"https://codeload.github.com/tagaryen/archer-net/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246547364,"owners_count":20794970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["encrypt-certificates","gmssl","http","libevent","networking","openssl","sm2"],"created_at":"2025-03-31T22:12:46.843Z","updated_at":"2025-05-12T13:04:37.316Z","avatar_url":"https://github.com/tagaryen.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# archer-net\r\nnetwork framework written native c, support latest openssl(gmssl) 1.3 \r\nsupport encrypted key and encrypted certificate  \r\nmaven:  \r\n``` maven\r\n    \u003cdependency\u003e\r\n\t  \u003cgroupId\u003eio.github.tagaryen\u003c/groupId\u003e  \r\n\t  \u003cartifactId\u003earcher-net\u003c/artifactId\u003e  \r\n\t  \u003cversion\u003e1.3.14\u003c/version\u003e  \r\n\t\u003c/dependency\u003e  \r\n``` maven\r\n\r\n## gmssl examples \r\n``` java \r\n    String root = getCurrentWorkDir();\r\n\r\n    String ca = root + \"crt/ca.crt\";\r\n    String key = root + \"crt/server.key\";\r\n    String crt = root + \"crt/server.crt\";\r\n    String enkey = root + \"crt/server_en.key\";\r\n    String encrt = root + \"crt/server_en.crt\";\r\n    String clikey = root + \"crt/cli.key\";\r\n    String clicrt = root + \"crt/cli.crt\";\r\n    String enclikey = root + \"crt/cli_en.key\";\r\n    String enclicrt = root + \"crt/cli_en.crt\";\r\n\r\n    //event loop\r\n    HandlerList handlerlist = new HandlerList();\r\n    handlerlist.add(\r\n        new FrameReadHandler(0, 2, 2),\r\n        new AbstractWrappedHandler\u003cMsg\u003e() {\r\n        @Override\r\n        public void onMessage(ChannelContext ctx, Msg input) {\r\n            System.out.println(\"Handler: receive: \" + input.data);\r\n        }\r\n        @Override\r\n        public Msg decode(Bytes in) {\r\n            Msg msg = new Msg();\r\n            msg.decode(in);\r\n            return msg;\r\n        }\r\n            \r\n        @Override\r\n        public void onConnect(ChannelContext ctx) {\r\n            Channel channel = ctx.channel();\r\n            String host = channel.remoteHost();\r\n            int port = channel.remotePort();\r\n            System.out.println(\"Handler: \" + host+\":\"+port+\" connected.\");\r\n            ctx.write(new Msg());\r\n        }\r\n        @Override\r\n        public void onDisconnect(ChannelContext ctx) {\r\n            Channel channel = ctx.channel();\r\n            String host = channel.remoteHost();\r\n            int port = channel.remotePort();\r\n            System.out.println(\"Handler: \" + host+\":\"+port+\" disconnected.\");\r\n        }\r\n        @Override\r\n        public void onError(ChannelContext ctx, Throwable t) {\r\n            t.printStackTrace();\r\n        }\r\n        @Override\r\n        public void onAccept(ChannelContext ctx) {\r\n            Channel channel = ctx.channel();\r\n            String host = channel.remoteHost();\r\n            int port = channel.remotePort();\r\n            System.out.println(host+\":\"+port+\" accepted.\");\r\n        }\r\n    });\r\n    try {\r\n        //ca crt\r\n        byte[] caBytes= Files.readAllBytes(Paths.get(ca));\r\n\r\n        //server crt\r\n        byte[] crtBytes= Files.readAllBytes(Paths.get(crt));\r\n        byte[] keyBytes= Files.readAllBytes(Paths.get(key));\r\n        byte[] enCrtBytes= Files.readAllBytes(Paths.get(encrt));\r\n        byte[] enKeyBytes= Files.readAllBytes(Paths.get(enkey));\r\n        //client crt\r\n        byte[] clicrtBytes= Files.readAllBytes(Paths.get(clicrt));\r\n        byte[] clikeyBytes= Files.readAllBytes(Paths.get(clikey));\r\n        byte[] enClicrtBytes= Files.readAllBytes(Paths.get(enclicrt));\r\n        byte[] enClikeyBytes= Files.readAllBytes(Paths.get(enclikey));\r\n\r\n        //start a gmssl server\r\n        System.out.println(\"start server.\");\r\n        SslContext opt = new SslContext(false, true).trustCertificateAuth(caBytes).useCertificate(crtBytes, keyBytes).useEncryptCertificate(enClicrtBytes, enClikeyBytes);\r\n        ServerChannel server = new ServerChannel(opt);\r\n        server.handlerList(handlerlist);\r\n        server.listen(\"127.0.0.1\", 8081);\r\n\r\n        // wait\r\n        Thread.sleep(1000);\r\n\r\n        //start a gmssl client\r\n        SslContext cliopt = new SslContext(true, false).trustCertificateAuth(caBytes).useCertificate(clicrtBytes, clikeyBytes).useEncryptCertificate(enClicrtBytes, enClikeyBytes);\r\n        Channel cli = new Channel(cliopt);\r\n        cli.handlerList(handlerlist);\r\n        cli.connect(\"127.0.0.1\", 8081);\r\n\r\n        //wait\r\n        Thread.sleep(2000);\r\n\r\n        //close client\r\n        cli.close();\r\n        \r\n    } catch (Exception e) {\r\n        e.printStackTrace();\r\n    }\r\n```\r\n## gmssl https server examples \r\n``` java\r\n    String root = getCurrentWorkDir();\r\n\r\n    String ca = root + \"crt/ca.crt\";\r\n    String key = root + \"crt/server.key\";\r\n    String crt = root + \"crt/server.crt\";\r\n    String enkey = root + \"crt/server_en.key\";\r\n    String encrt = root + \"crt/server_en.crt\";\r\n    \r\n    byte[] crtBytes= Files.readAllBytes(Paths.get(crt));\r\n    byte[] keyBytes= Files.readAllBytes(Paths.get(key));\r\n    byte[] enCrtBytes= Files.readAllBytes(Paths.get(encrt));\r\n    byte[] enKeyBytes= Files.readAllBytes(Paths.get(enkey));\r\n\r\n    System.out.println(\"start server.\");\r\n    \r\n    HandlerList handlerlist = new HandlerList();\r\n    handlerlist.add(new HttpWrappedHandler() {\r\n        @Override\r\n        public void handle(HttpRequest req, HttpResponse res) throws Exception {\r\n            String uri = req.getUri();\r\n            res.setContentType(ContentType.APPLICATION_JSON);\r\n            if(uri.equals(\"/nihao\")) {\r\n            res.setStatus(HttpStatus.OK);\r\n            res.setContent(\"{\\\"nihao\\\":\\\"ni\\\"}\".getBytes());\r\n        } else {\r\n            res.setStatus(HttpStatus.NOT_FOUND);\r\n            res.setContent(\"{\\\"nihao\\\":\\\"ni\\\"}\".getBytes());\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void handleException(HttpRequest req, HttpResponse res, Throwable t) {\r\n        t.printStackTrace();\r\n        String body = \"{\" +\r\n            \"\\\"server\\\": \\\"Java/\"+System.getProperty(\"java.version\")+\"\\\",\" +\r\n            \"\\\"time\\\": \\\"\" + LocalDateTime.now().toString() + \"\\\",\" +\r\n            \"\\\"status\\\": \\\"\" + HttpStatus.SERVICE_UNAVAILABLE.getStatus() + \"\\\"\" +\r\n            \"}\";\r\n\r\n        res.setStatus(HttpStatus.SERVICE_UNAVAILABLE);\r\n        res.setContentType(ContentType.APPLICATION_JSON);\r\n        res.setContent(body.getBytes());\r\n        }\r\n    });\r\n\r\n    SslContext opt = new SslContext().trustCertificateAuth(caBytes).useCertificate(crtBytes, keyBytes);\r\n    ServerChannel server = new ServerChannel(opt);\r\n    server.handlerList(handlerlist);\r\n    server.listen(8080);\r\n```\r\nor \r\n``` java\r\n    String root = getCurrentWorkDir();\r\n\r\n    String ca = root + \"crt/ca.crt\";\r\n    String key = root + \"crt/server.key\";\r\n    String crt = root + \"crt/server.crt\";\r\n    String enkey = root + \"crt/server_en.key\";\r\n    String encrt = root + \"crt/server_en.crt\";\r\n    try {\r\n        byte[] caBytes= Files.readAllBytes(Paths.get(ca));\r\n        byte[] crtBytes= Files.readAllBytes(Paths.get(crt));\r\n        byte[] keyBytes= Files.readAllBytes(Paths.get(key));\r\n        byte[] enCrtBytes= Files.readAllBytes(Paths.get(encrt));\r\n        byte[] enKeyBytes= Files.readAllBytes(Paths.get(enkey));\r\n        \r\n        System.out.println(\"start server.\");\r\n        SslContext opt = new SslContext(false).trustCertificateAuth(caBytes).useCertificate(crtBytes, keyBytes).useEncryptCertificate(enCrtBytes, enKeyBytes);\r\n        HttpServer server = new HttpServer(opt);\r\n        server.listen(\"127.0.0.1\", 8081, new HttpWrappedHandler() {\r\n\r\n        @Override\r\n        public void handle(HttpRequest req, HttpResponse res) throws Exception {\r\n            //do something here\r\n        }\r\n\r\n        @Override\r\n        public void handleException(HttpRequest req, HttpResponse res, Throwable t) {\r\n            t.printStackTrace();\r\n        }\r\n        });\r\n    } catch(Exception e) {\r\n        e.printStackTrace();\r\n    }    \r\n```\r\n\r\n## http(s) client examples \r\n``` java\r\n    NativeResponse baidu = NativeRequest.get(\"https://www.baidu.com\");\r\n    System.out.println(baidu.getStatus());\r\n    System.out.println(new String(baidu.getBody()));\r\n\r\n    //request localhost (above server) \r\n    String root = getCurrentWorkDir();\r\n    String ca = root + \"crt/ca.crt\";\r\n    NativeResponse localhost = NativeRequest.get(\"https://127.0.0.1:8080/hihao\", new NativeRequest.Options().caPath(ca));\r\n    System.out.println(localhost.getStatus());\r\n    System.out.println(new String(localhost.getBody()));\r\n``` \r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftagaryen%2Farcher-net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftagaryen%2Farcher-net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftagaryen%2Farcher-net/lists"}