Skip to content

Commit

Permalink
#39 test Mutual tls not work
Browse files Browse the repository at this point in the history
  • Loading branch information
peacess committed Feb 2, 2021
2 parents 4547807 + c14fe03 commit ea34693
Show file tree
Hide file tree
Showing 26 changed files with 2,628 additions and 755 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,6 @@ demo/rbatis_demo/target
/app/libwallets_cdl.so
/packages/services/before.log
/packages/services/log.log
/bc/wallets_cdl/src/wallets_c.h
/packages/services/test/greeter/greeter_go/greeter_go/before.log
/packages/services/test/greeter/greeter_go/greeter_go/log.log
4 changes: 2 additions & 2 deletions packages/services/lib/services.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library services;

export 'src/enum_const.dart';
export 'src/rpc_client/channel_credentials.dart';
export 'src/rpc_client/client_channel.dart';
export 'src/rpc_client/refresh.dart';
export 'src/enum_const.dart';

4 changes: 2 additions & 2 deletions packages/services/lib/src/enum_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ enum AppPlatformType {
}

extension AppPlatformTypeEx on AppPlatformType {

static AppPlatformType from(String chainType) {
AppPlatformType re;
switch (chainType) {
Expand Down Expand Up @@ -62,7 +61,8 @@ extension AppPlatformTypeEx on AppPlatformType {
String re;
switch (this) {
case AppPlatformType.any:
re = "any";break;
re = "any";
break;
case AppPlatformType.aarch64_linux_android:
re = "aarch64_linux_android";
break;
Expand Down
27 changes: 27 additions & 0 deletions packages/services/lib/src/rpc_client/channel_credentials.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:io';

import 'package:grpc/grpc.dart';

class ChannelCredentialsEx extends ChannelCredentials {
List<int> certBytes;
List<int> keyBytes;
List<int> chainBytes;

ChannelCredentialsEx(this.certBytes, this.keyBytes, this.chainBytes,
{BadCertificateHandler onBadCertificate})
: super.secure(onBadCertificate: onBadCertificate);

@override
SecurityContext get securityContext {
// SecurityContext context = new SecurityContext(withTrustedRoots: true);
// context.setAlpnProtocols(supportedAlpnProtocols, false);
//
// // context.setTrustedCertificatesBytes(certBytes);
// context.usePrivateKeyBytes(keyBytes);
// context.useCertificateChainBytes(chainBytes);

SecurityContext context = new SecurityContext(withTrustedRoots: true);
context.setTrustedCertificatesBytes(certBytes);
return context;
}
}
21 changes: 13 additions & 8 deletions packages/services/lib/src/rpc_client/refresh.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'package:grpc/grpc.dart';
import 'package:meta/meta.dart';
import 'package:services/services.dart';
Expand All @@ -9,17 +8,23 @@ class Refresh {
RefreshFaceClient _client;
Refresh_RefreshReq _req;
static Refresh _instance;

Refresh._internal();
factory Refresh.get(ConnectParameter parameter, String version, AppPlatformType platformType){
if(_instance == null) {

factory Refresh.get(ConnectParameter parameter, String version,
AppPlatformType platformType) {
if (_instance == null) {
_instance = Refresh._internal();
_instance._channel = new ClientChannel(
parameter.host,
port: parameter.port,
options: const ChannelOptions(credentials: ChannelCredentials.insecure(), connectionTimeout: Duration(minutes: 1)),
options: const ChannelOptions(
credentials: ChannelCredentials.insecure(),
connectionTimeout: Duration(minutes: 1)),
);
_instance._client = new RefreshFaceClient(_instance._channel);
_instance._req = Refresh_RefreshReq(version:version,appPlatformType: platformType.toEnumString());
_instance._req = Refresh_RefreshReq(
version: version, appPlatformType: platformType.toEnumString());
}
return _instance;
}
Expand All @@ -29,10 +34,11 @@ class Refresh {

Future<ConnectParameter> refreshCall() async {
var res = await _client.refresh(_req);
if(res.hasErr()){
if (res.hasErr()) {
return null;
}
ConnectParameter parameter = new ConnectParameter(res.serviceMeta.host, res.serviceMeta.port.toInt());
ConnectParameter parameter = new ConnectParameter(
res.serviceMeta.host, res.serviceMeta.port.toInt());
return parameter;
}

Expand All @@ -42,4 +48,3 @@ class Refresh {
_channel = null;
}
}

0 comments on commit ea34693

Please sign in to comment.