-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added New Sections Related To Memory Management, Communication Security and Process Management #91
base: master
Are you sure you want to change the base?
Changes from all commits
16e6a66
e7f4998
a8b6ebc
8171ed4
4a5742a
34d5df4
598bb1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||||||||||
package main | ||||||||||||
|
||||||||||||
import ( | ||||||||||||
"context" | ||||||||||||
"crypto/tls" | ||||||||||||
"crypto/x509" | ||||||||||||
"flag" | ||||||||||||
"fmt" | ||||||||||||
"io/ioutil" | ||||||||||||
"log" | ||||||||||||
pb "pentest/grpc/samplebuff" | ||||||||||||
"time" | ||||||||||||
|
||||||||||||
"google.golang.org/grpc" | ||||||||||||
"google.golang.org/grpc/credentials" | ||||||||||||
) | ||||||||||||
|
||||||||||||
const ( | ||||||||||||
defaultName = "Art Rosenbaum" | ||||||||||||
) | ||||||||||||
|
||||||||||||
var ( | ||||||||||||
addr = flag.String("addr", "localhost:10001", "Address of Server") | ||||||||||||
name = flag.String("name", defaultName, "Name to greet") | ||||||||||||
) | ||||||||||||
|
||||||||||||
func main() { | ||||||||||||
flag.Parse() | ||||||||||||
b, _ := ioutil.ReadFile("../cert/ca.cert") | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: let's promote best practice of not skipping errors
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anatolym Shouldn't the error message be "Couldn't read ca.cert: %v", instead? |
||||||||||||
cp := x509.NewCertPool() | ||||||||||||
if !cp.AppendCertsFromPEM(b) { | ||||||||||||
fmt.Println("credentials: failed to append certificates") | ||||||||||||
} | ||||||||||||
|
||||||||||||
config := &tls.Config{ | ||||||||||||
InsecureSkipVerify: false, | ||||||||||||
RootCAs: cp, | ||||||||||||
} | ||||||||||||
|
||||||||||||
creds := credentials.NewTLS(config) | ||||||||||||
// Set up a connection to the server. | ||||||||||||
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(creds)) | ||||||||||||
if err != nil { | ||||||||||||
log.Fatalf("Could not connect to server: %v", err) | ||||||||||||
} | ||||||||||||
defer conn.Close() | ||||||||||||
c := pb.NewSampleServiceClient(conn) | ||||||||||||
|
||||||||||||
// Contact the server and print out its response. | ||||||||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||||||||||||
defer cancel() | ||||||||||||
r, err := c.Greet(ctx, &pb.SendMsg{Name: *name}) | ||||||||||||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: fmt
Suggested change
|
||||||||||||
if err != nil { | ||||||||||||
log.Fatalf("could not send message: %v", err) | ||||||||||||
} | ||||||||||||
log.Printf("Sending message: %s", r.GetMessage()) | ||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||||||||||||||||||||
package main | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||
"context" | ||||||||||||||||||||||||
"flag" | ||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||
"log" | ||||||||||||||||||||||||
"net" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
pb "pentest/grpc/samplebuff" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
"google.golang.org/grpc" | ||||||||||||||||||||||||
"google.golang.org/grpc/credentials" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
var ( | ||||||||||||||||||||||||
port = flag.Int("port", 10001, "The server port") | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// server is used to implement sample.GreeterServer. | ||||||||||||||||||||||||
type server struct { | ||||||||||||||||||||||||
pb.UnimplementedSampleServiceServer | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would suggest not embedding gRPC service interface to a structure like this. The issue is that this implicitly says the Instead, we can enforce interface implementation check on the compile time like this.
Suggested change
Note, the interface implementation check will be implicitly performed by compiler by the |
||||||||||||||||||||||||
|
||||||||||||||||||||||||
// Greet implements sample.GreeterServer | ||||||||||||||||||||||||
func (s *server) Greet(ctx context.Context, in *pb.SendMsg) (*pb.SendResp, error) { | ||||||||||||||||||||||||
log.Printf("Received msg: %v", in.GetName()) | ||||||||||||||||||||||||
return &pb.SendResp{Message: "Hey " + in.GetName()}, nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func main() { | ||||||||||||||||||||||||
flag.Parse() | ||||||||||||||||||||||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) | ||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||
log.Fatalf("Could not start the server: %v", err) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
//Configuring the certificates | ||||||||||||||||||||||||
creds, err := credentials.NewServerTLSFromFile("../cert/service.pem", "../cert/service.key") | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||
log.Fatalf("TLS setup failed: %v", err) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: fmt
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
s := grpc.NewServer(grpc.Creds(creds)) | ||||||||||||||||||||||||
pb.RegisterSampleServiceServer(s, &server{}) | ||||||||||||||||||||||||
log.Printf("Server started at: %v", lis.Addr()) | ||||||||||||||||||||||||
if err := s.Serve(lis); err != nil { | ||||||||||||||||||||||||
log.Fatalf("Could not start the server: %v", err) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
|
||
option go_package = "github.com/pypalkar23/go-rpc-cis5209/sample"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps, this name should be changed to something else like |
||
|
||
package sample; | ||
|
||
|
||
service SampleService { | ||
rpc Greet (SendMsg) returns (SendResp); | ||
} | ||
|
||
message SendMsg { | ||
string name = 1; | ||
} | ||
|
||
message SendResp{ | ||
string message = 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fmt