提交 9bffcfcb 编写于 作者: J jiazhiguang 提交者: jia zhang

adapt to occlum 0.14

上级 912cf014
...@@ -4,6 +4,10 @@ type Containerd struct { ...@@ -4,6 +4,10 @@ type Containerd struct {
Socket string `toml:"socket"` Socket string `toml:"socket"`
} }
type Signature struct {
ServerAddress string `toml:"server_address"`
}
type Occlum struct { type Occlum struct {
BuildImage string `toml:"build_image"` BuildImage string `toml:"build_image"`
EnclaveRuntimePath string `toml:"enclave_runtime_path"` EnclaveRuntimePath string `toml:"enclave_runtime_path"`
...@@ -21,5 +25,6 @@ type Config struct { ...@@ -21,5 +25,6 @@ type Config struct {
LogLevel string `toml:"log_level"` LogLevel string `toml:"log_level"`
SgxToolSign string `toml:"sgx_tool_sign"` SgxToolSign string `toml:"sgx_tool_sign"`
Containerd Containerd `toml:"containerd"` Containerd Containerd `toml:"containerd"`
Signature Signature `toml:"signature"`
EnclaveRuntime EnclaveRuntime `toml:"enclave_runtime"` EnclaveRuntime EnclaveRuntime `toml:"enclave_runtime"`
} }
...@@ -169,6 +169,13 @@ function buildUnsignedEnclave(){ ...@@ -169,6 +169,13 @@ function buildUnsignedEnclave(){
/bin/bash ${base_dir}/replace_occlum_image.sh ${rootfs} image /bin/bash ${base_dir}/replace_occlum_image.sh ${rootfs} image
# occlum build # occlum build
occlum build occlum build
if [ ! -f .occlum/build/lib/libocclum-libos.so ]; then
if [ -f .occlum/build/lib/libocclum-libos.so.0 ]; then
pushd .occlum/build/lib/
ln -s libocclum-libos.so.0 libocclum-libos.so
popd
fi
fi
mkdir -p ${rootfs}/${work_dir} || true mkdir -p ${rootfs}/${work_dir} || true
/bin/cp -fr .occlum ${rootfs}/${work_dir} /bin/cp -fr .occlum ${rootfs}/${work_dir}
/bin/cp -f Enclave.xml ${rootfs}/${work_dir} /bin/cp -f Enclave.xml ${rootfs}/${work_dir}
......
...@@ -18,11 +18,12 @@ func (s *ApiServer) installRoutes() { ...@@ -18,11 +18,12 @@ func (s *ApiServer) installRoutes() {
{ {
g.POST("/pkcs1", s.pkcs1Handler) g.POST("/pkcs1", s.pkcs1Handler)
} }
r.Use(loggerHandleFunc).GET("/api/v1/publickey", s.publicKeyHandler)
} }
} }
func (s ApiServer) installHealthz() { func (s ApiServer) installHealthz() {
r := s.router r := s.router
r.GET("/ping", func(c *gin.Context) { c.String(http.StatusOK, "pong") }) r.GET("/ping", func(c *gin.Context) { c.String(http.StatusOK, "ping") })
r.GET("/healthz", func(c *gin.Context) { c.String(http.StatusOK, "ok") }) r.GET("/healthz", func(c *gin.Context) { c.String(http.StatusOK, "ok") })
} }
...@@ -5,8 +5,6 @@ import ( ...@@ -5,8 +5,6 @@ import (
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/sha256" "crypto/sha256"
"crypto/x509"
"encoding/pem"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
...@@ -37,9 +35,22 @@ func (s *ApiServer) pkcs1Handler(c *gin.Context) { ...@@ -37,9 +35,22 @@ func (s *ApiServer) pkcs1Handler(c *gin.Context) {
} }
payload.Signature = string(signedBytes) payload.Signature = string(signedBytes)
payload.PublicKey = string(pem.EncodeToMemory(&pem.Block{ bytes, err := ioutil.ReadFile(s.publicKeyFilePath)
Type: "RSA PUBLIC KEY", if err != nil {
Bytes: x509.MarshalPKCS1PublicKey(s.publicKey), glog.Errorf("failed to parse public key, public key path: %s, err:%v", s.publicKeyFilePath, err.Error())
})) c.AbortWithStatus(http.StatusInternalServerError)
return
}
payload.PublicKey = string(bytes)
c.JSON(http.StatusOK, payload) c.JSON(http.StatusOK, payload)
} }
func (s *ApiServer) publicKeyHandler(c *gin.Context) {
bytes, err := ioutil.ReadFile(s.publicKeyFilePath)
if err != nil {
glog.Errorf("failed to parse public key, public key path: %s, err:%v", s.publicKeyFilePath, err.Error())
c.AbortWithStatus(http.StatusInternalServerError)
return
}
c.JSON(http.StatusOK, string(bytes))
}
...@@ -10,11 +10,13 @@ import ( ...@@ -10,11 +10,13 @@ import (
) )
type ApiServer struct { type ApiServer struct {
router *gin.Engine router *gin.Engine
listenAddr string listenAddr string
privateKey *rsa.PrivateKey privateKey *rsa.PrivateKey
publicKey *rsa.PublicKey publicKey *rsa.PublicKey
certificate *x509.Certificate certificate *x509.Certificate
publicKeyFilePath string
privateKeyFilePath string
} }
func NewApiServer(listenAddr string, conf *conf.Config) (*ApiServer, error) { func NewApiServer(listenAddr string, conf *conf.Config) (*ApiServer, error) {
...@@ -27,10 +29,12 @@ func NewApiServer(listenAddr string, conf *conf.Config) (*ApiServer, error) { ...@@ -27,10 +29,12 @@ func NewApiServer(listenAddr string, conf *conf.Config) (*ApiServer, error) {
return nil, err return nil, err
} }
s := &ApiServer{ s := &ApiServer{
router: gin.Default(), router: gin.Default(),
listenAddr: listenAddr, listenAddr: listenAddr,
privateKey: privateKey, privateKey: privateKey,
publicKey: publicKey, publicKey: publicKey,
publicKeyFilePath: conf.PublicKeyPath,
privateKeyFilePath: conf.PrivateKeyPath,
} }
s.installRoutes() s.installRoutes()
return s, nil return s, nil
......
package v2 package v2
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"net/url" "net/url"
"os" "os"
...@@ -8,12 +9,13 @@ import ( ...@@ -8,12 +9,13 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"github.com/alibaba/inclavare-containers/shim/runtime/config" "github.com/BurntSushi/toml"
shim_config "github.com/alibaba/inclavare-containers/shim/config"
"github.com/alibaba/inclavare-containers/shim/runtime/carrier" "github.com/alibaba/inclavare-containers/shim/runtime/carrier"
emptycarrier "github.com/alibaba/inclavare-containers/shim/runtime/carrier/empty" emptycarrier "github.com/alibaba/inclavare-containers/shim/runtime/carrier/empty"
"github.com/alibaba/inclavare-containers/shim/runtime/carrier/graphene" "github.com/alibaba/inclavare-containers/shim/runtime/carrier/graphene"
"github.com/alibaba/inclavare-containers/shim/runtime/carrier/occlum" "github.com/alibaba/inclavare-containers/shim/runtime/carrier/occlum"
"github.com/alibaba/inclavare-containers/shim/runtime/config"
signclient "github.com/alibaba/inclavare-containers/shim/runtime/signature/client" signclient "github.com/alibaba/inclavare-containers/shim/runtime/signature/client"
"github.com/alibaba/inclavare-containers/shim/runtime/v2/rune" "github.com/alibaba/inclavare-containers/shim/runtime/v2/rune"
"github.com/alibaba/inclavare-containers/shim/runtime/v2/rune/constants" "github.com/alibaba/inclavare-containers/shim/runtime/v2/rune/constants"
...@@ -86,19 +88,32 @@ func (s *service) carrierMain(req *taskAPI.CreateTaskRequest) (carrier.Carrier, ...@@ -86,19 +88,32 @@ func (s *service) carrierMain(req *taskAPI.CreateTaskRequest) (carrier.Carrier,
var signatureFile string var signatureFile string
if carrierKind != rune.Empty { if carrierKind != rune.Empty {
//TODO: Retry on failture. //TODO: Retry on failture.
/*publicKey, signature, err := remoteSign("https://10.0.8.126:8443/api/v1/signature", commonArgs.Enclave) var cfg shim_config.Config
defer os.RemoveAll(path.Dir(publicKey))*/ var publicKey, signature string
//FIXME mock signature if _, err := toml.DecodeFile(constants.ConfigurationPath, &cfg); err != nil {
return carr, err
}
materialRealPath := signingMaterial materialRealPath := signingMaterial
if carrierKind == rune.Occlum { if carrierKind == rune.Occlum {
materialRealPath = filepath.Join(req.Bundle, signingMaterial) materialRealPath = filepath.Join(req.Bundle, signingMaterial)
} }
publicKey, signature, err := mockSign(materialRealPath) if cfg.Signature.ServerAddress == "" {
if err != nil { publicKey, signature, err = mockSign(materialRealPath)
logrus.Errorf("carrierMain: mock sign failed. error: %++v", err) if err != nil {
return carr, err logrus.Errorf("carrierMain: mock sign failed. error: %++v", err)
return carr, err
}
defer os.RemoveAll(path.Dir(publicKey))
} else {
publicKey, signature, err = remoteSign(fmt.Sprintf("%s/api/v1/signature",
cfg.Signature.ServerAddress), materialRealPath)
if err != nil {
logrus.Errorf("carrierMain: get signature failed. server address: %s. error: %++v",
cfg.Signature.ServerAddress, err)
return carr, err
}
defer os.RemoveAll(path.Dir(publicKey))
} }
defer os.RemoveAll(path.Dir(publicKey))
commonArgs.Key = publicKey commonArgs.Key = publicKey
signatureFile = signature signatureFile = signature
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册