首页 > 其他分享 >【grpc】配置

【grpc】配置

时间:2023-11-21 11:13:32浏览次数:33  
标签:配置 grpc req openssl cnf key test

@

目录


写在前面

  • 相关博文
  • 个人博客首页
  • 免责声明:仅供学习交流使用!开源框架可能存在的风险和相关后果将完全由用户自行承担,本人不承担任何法律责任。

grpc 环境搭建

go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
git clone -b v1.57.0 --depth 1 https://github.com/grpc/grpc-go

proto

// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// 版本
syntax = "proto3";
// golang 代码生成路径
option go_package = "./gorpc;";

// 包名称
package gorpc;

// 注册的服务名称
// rpc 是对应的方法 
// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloResponse) {}
}

// 请求结构体
// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// 返回结构体
// The response message containing the greetings
message HelloResponse {
  string message = 1;
}


证书

1. 生成 rsa key

openssl genrsa -des3 -out server.key 2048

2. 生成 ca crt

openssl req -new -x509 -key server.key -out ca.crt -days 3650

3. 生成 csr

openssl req -new -key server.key -out server.csr

4. openssl.cnf (/usr/lib/ssl/openssl.cnf) 【WINDOWS 默认为 openssl.cfg

1)复制一份你安装的openssl的bin目录里面的openssl.cnf 
2)找到 [ CA_default ],打开 copy_extensions = copy (就是把前面的#去掉)
3)找到[ req ],打开 req_extensions = v3_req # The extensions to add to a certificate request
4)找到[ v3_req ],添加 subjectAltName = @alt_names
5)添加新的标签 [ alt_names ],和标签字段
DNS.1 = *.org.haha.com
DNS.2 = *.haha.com

5. 生成证书私钥 test.key

openssl genpkey -algorithm RSA -out test.key

6. 通过私钥test.key生成证书请求文件test.csr(注意cfg和cnf)

openssl req -new -nodes -key test.key -out test.csr -days 3650 -subj "/C=cn/OU=myorg/O=mycomp/CN=myname" -config ./openssl.cnf -extensions v3_req
test.csr是上面生成的证书请求文件。
ca.crt/server.key 是CA证书文件和key,用来对test.csr进行签名认证。这两个文件在第一部分生成。

7.生成SAN证书

openssl x509 -req -days 365 -in test.csr -out test.pem -CA ca.crt -CAkey server.key -CAcreateserial -extfile ./openssl.cnf -extensions v3_req

然后就可以用在 GO 1.15 以上版本的GRPC通信了

服务器加载代码

creds, err := credentials.NewServerTLSFromFile("test.pem", "test.key")

客户端加载代码

creds,err := credentials.NewClientTLSFromFile("test.pem","*.org.haha.com")

参考资料


交个朋友

  • github learnselfs

标签:配置,grpc,req,openssl,cnf,key,test
From: https://www.cnblogs.com/nones/p/17625760.html

相关文章

  • 02-MySQL的安装与配置(Windows)
    MySQL数据库MySQL关是一种关系数据库管理系统,所使用的SQL语言是用于访问数据库的最常用的标准化语言,其特点为体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,在Web应用方面MySQL是最好的RDBMS(RelationalDatabaseManagementSystem:关系数据库管理系统)应用软件之......
  • 前端配置、跨域、扩写用户表、轮播图
    luffy项目前端配置#1跟后端交互:axios cnpminstall-Saxios 以后想发送ajax请求,必须导入,使用可以把axios放到vue实例中,以后任意组件中this.$axios.get() main.js中加入importaxiosfrom'axios' Vue.prototype.$axios=axios;#2操作cookie:vue-cookies......
  • Nginx实现基于请求头的访问控制配置
    在Nginx中,可以使用"allow"和"deny"指令来实现IP访问限制。"allow"指令用于允许特定的IP地址或IP地址段访问服务器,"deny"指令用于阻止特定的IP地址或IP地址段访问服务器。以下是一个简单的配置示例:复制12345location/{    deny192.168.0.1;    allow19......
  • Nginx实现基于IP地址的访问控制配置
    一、Nginx配置中的IP地址变量在Nginx的配置文件中,通过一些变量来表示客户端的IP地址。其中最常用的是$remote_addr变量,它代表了客户端的IP地址。二、简单的IP地址过滤配置允许特定IP地址访问复制1234location/{  allow192.168.1.100;  denyall;}......
  • Nginx实现基于请求URL的请求重写配置
    在Nginx中,可以使用rewrite指令来进行请求重写。其基本语法如下:复制1rewriteregexreplacement[flag];其中,regex表示正则表达式,用于匹配当前请求URL;replacement表示目标URL,替换原来的URL;flag是可选的标志位,用于控制重写的行为。例如,下面的重写规则可以将以“/pa......
  • Nginx限制IP访问配置,提升网站安全性
    Nginx限制IP访问配置,提升网站安全性随着互联网的快速发展,网络安全问题逐渐受到人们的重视。对于网站管理员来说,确保服务器的安全是非常重要的。Nginx作为一款高性能的Web服务器,具有灵活的配置选项,可以通过限制IP访问来提升网站的安全性。本文将介绍如何在Nginx中配置IP访问限制,并......
  • Nginx实现Cookie的访问控制配置
    通过基于Cookie的访问控制配置,可以限制用户访问特定的页面或资源。本文将介绍如何使用Nginx来实现这样的访问控制,并给出具体的代码示例。开启Nginx的http_auth_request模块首先,需要确保Nginx已经启用了http_auth_request模块。如果没有启用,可以通过编辑Nginx配置文件添加该模块。......
  • VSCode 配置C#
    引用:https://blog.csdn.net/weixin_43729127/article/details/1277403111.安装扩展 .netcoreSDK,扩展C/C++,C#Extensions,C#,CodeRunner2.创建项目新建文件夹,终端->新建终端,命令行输入dotnetnewconsole 3.配置环境设置->用户->扩展->RunCodeConfigu......
  • day131- springboot 的配置文件yaml的用法
    springboot的配置文件yaml的用法yaml文件同properties文件一样,适合用来做数据为中心的配置文件基本语法key:value;kv之间有空格大小写敏感使用缩进表示层级关系缩进不允许使用tab,只允许空格缩进的空格数不重要,只要相同层级的元素左对齐即可'#'表示注释字......
  • 配置impala自动同步HMS元数据
    由于Impala的AutomaticInvalidate/RefreshMetadata的功能在CDH6.3版本才有的功能,通过以上两个升级,已经具备的该功能,下面是需要配置该功能测试环境1.CM和CDH版本为6.1.1(hive的版本升级到了CDH6.3.2-2.1.1)2.操作系统版本为RedHat7.63.impala3.4版本操作步骤进入CM界面>Hive......