Example #1
0
// ConvertDER2PEM convert a certificate from DER to PEM format
func ConvertDER2PEM(derFile, pemFile string) error {
	path, err := CheckInstalled()
	app.CheckPanic(err)

	cmd := exec.Command(path, "pkcs7", "-print_certs", "-inform", "der", "-in", derFile, "-outform", "pem", "-out", pemFile)
	cmd.Stderr = os.Stderr

	err = cmd.Run()
	app.CheckPanic(err)

	return nil
}
Example #2
0
// Verify the messagFile with the signatureFile by the certificate
func Verify(pemFile, signatureFile, messageFile string) error {
	path, err := CheckInstalled()
	app.CheckPanic(err)

	cmd := exec.Command(path, "smime", "-verify", "-inform", "der", "-in", signatureFile, "-content", messageFile, "-certfile", pemFile, "-noverify")
	if app.IsDebugRunmode() {
		cmd.Stderr = os.Stderr
	}

	err = cmd.Run()
	app.CheckPanic(err)

	return nil
}
Example #3
0
// ExportPubkey expors the public key from certificate
func ExportPubkey(pemFile, pubkeyFile string) error {
	path, err := CheckInstalled()
	app.CheckPanic(err)

	cmd := exec.Command(path, "x509", "-pubkey", "-noout", "-in", pemFile, "-outform", "pem")
	if app.IsDebugRunmode() {
		cmd.Stderr = os.Stderr
	}

	err = cmd.Run()
	app.CheckPanic(err)

	pubkey, _ := cmd.Output()

	err = ioutil.WriteFile(pubkeyFile, pubkey, 0644)
	app.CheckPanic(err)

	return nil
}
Example #4
0
func InitDB(init bool, prefill bool) {
	orm.Debug = app.IsDebugRunmode()
	orm.DefaultTimeLoc = time.Local

	orm.RegisterModel(new(Contrep), new(Document), new(Component))
	orm.RegisterDataBase("default", beego.AppConfig.String(DB_DRIVER), beego.AppConfig.String(DB_CONN))

	err := orm.RunSyncdb("default", init, true)
	app.CheckPanic(err)

	Orm = orm.NewOrm()
	Orm.Using("default")

	if prefill {
		contrep := &Contrep{Name: "MP", Desc: "Description of MP content repository", IsOnline: true, IsCertChecked: true}
		_, err := Orm.Insert(contrep)
		app.CheckPanic(err)

		var documents []*Document

		for i := 0; i < 10; i++ {
			document := &Document{Name: "Document #" + strconv.Itoa(i)}
			_, err = Orm.Insert(document)
			app.CheckPanic(err)

			documents = append(documents, document)

			for j := 0; j < 10; j++ {
				component := &Component{Name: "Componet #" + strconv.Itoa(j) + " of Document " + document.Name}
				component.Document = document

				_, err = Orm.Insert(component)
				app.CheckPanic(err)
			}
		}
	}
}
Example #5
0
func (c *Archivelink) putCert() {
	var pis = ParameterInfos{
		CONTREP:   ParameterInfo{optmand: MANDATORY},
		P_VERSION: ParameterInfo{optmand: MANDATORY},
		AUTHID:    ParameterInfo{optmand: MANDATORY},
	}

	if c.check(PUTCERT, &pis) {
		contrep := models.Contrep{Name: c.Param(CONTREP)}

		err := models.Orm.Read(&contrep, "NAme")
		if err != orm.ErrNoRows {
			defer c.Ctx.Request.Body.Close()

			body, err := ioutil.ReadAll(c.Ctx.Request.Body)
			app.CheckPanic(err)

			derFile, err := app.CreateTempFile()
			app.CheckPanic(err)

			derFile.Write(body)
			derFile.Close()

			pemFilename, err := app.CreateTempFilename()
			app.CheckPanic(err)

			err = openssl.ConvertDER2PEM(derFile.Name(), pemFilename)
			app.CheckPanic(err)

			beego.Debug("read ConvertDER2PEM PEM file")

			pem, err := ioutil.ReadFile(pemFilename)
			app.CheckPanic(err)

			if contrep.IsCertProtected {
				contrep.ReceivedCert = string(pem)
				contrep.ReceivedCertDatetime = time.Now()
			} else {
				contrep.Cert = string(pem)
				contrep.CertDatetime = time.Now()
			}

			_, err = models.Orm.Update(&contrep)
			app.CheckPanic(err)
		} else {
			c.CustomAbort(406, app.Translate("Unknown Content Repository %s", c.Param(CONTREP)))
		}
	}
}